VC6.0用ODBC连接数据库如何添加记录?
1个回答
2013-05-23
展开全部
用sql语句执行就行。下面这个是我的部分代码,已经实现了。 -----------_bstr_t bstrSql="insert into Attendance(CheckDate,DateState,MStartTime,EmployeeID,CheckYear,DepartmentID,EmployName,Travell,Levell,MEndTime,Remark) values('";
bstrSql+=bstrDay;
bstrSql+=_bstr_t("','");
bstrSql+=bstrDateState;
bstrSql+=_bstr_t("','");
bstrSql+=bstrStartTime;
bstrSql+=_bstr_t("','");
bstrSql+=employeeid;
bstrSql+=_bstr_t("','");
bstrSql+=bstrYear;
bstrSql+=_bstr_t("','");
bstrSql+=bstrDepartmentID;
bstrSql+=_bstr_t("','");
bstrSql+=bstrUserName;
bstrSql+=_bstr_t("','");
bstrSql+=_bstr_t("0");
bstrSql+=_bstr_t("',");
bstrSql+=("NULL");
bstrSql+=_bstr_t(",'");
bstrSql+=bstrDay;
bstrSql+=_bstr_t("',");
bstrSql+=_bstr_t("' ')"); //作为新纪录加入数据库
try
{
conPtr1->Execute(bstrSql,NULL,adCmdText);//这个就是你要的插入操作。
conPtr1->Close();
}
catch(_com_error e)
{
conPtr1->Close();
}
bstrSql+=bstrDay;
bstrSql+=_bstr_t("','");
bstrSql+=bstrDateState;
bstrSql+=_bstr_t("','");
bstrSql+=bstrStartTime;
bstrSql+=_bstr_t("','");
bstrSql+=employeeid;
bstrSql+=_bstr_t("','");
bstrSql+=bstrYear;
bstrSql+=_bstr_t("','");
bstrSql+=bstrDepartmentID;
bstrSql+=_bstr_t("','");
bstrSql+=bstrUserName;
bstrSql+=_bstr_t("','");
bstrSql+=_bstr_t("0");
bstrSql+=_bstr_t("',");
bstrSql+=("NULL");
bstrSql+=_bstr_t(",'");
bstrSql+=bstrDay;
bstrSql+=_bstr_t("',");
bstrSql+=_bstr_t("' ')"); //作为新纪录加入数据库
try
{
conPtr1->Execute(bstrSql,NULL,adCmdText);//这个就是你要的插入操作。
conPtr1->Close();
}
catch(_com_error e)
{
conPtr1->Close();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询