如何向mssqlserver2000数据库中插入datatime/smalldatatime/timestamp类型?使用odbc API!
问题:1。如何绑定上述的3种类型?
2。如何插入上述类型。
我是用如下方法:
char *pSql="INSERT INTO time VALUES(?)";
retcode = SQLPrepare(hstmt,(unsigned char*)pSql,SQL_NTS);
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{
SQL_TIMESTAMP_STRUCT Time;
int len=sizeof(SQL_TIMESTAMP_STRUCT);
Time.year=1920;
Time.month=8;
Time.day=12;
Time.hour=2;
Time.minute=12;
Time.second=0;
Time.fraction=0;
memcpy(pt,&Time,sizeof(SQL_TIMESTAMP_STRUCT));
retcode=SQLBindParameter(hstmt,1,SQL_PARAM_INPUT, SQL_C_TIMESTAMP,SQL_TIMESTAMP,16,0,
pt,0,(long*)len);
if(retcode==SQL_SUCCESS)
AfxMessageBox("Bind Sucess!");
if(SQLExecute(hstmt)==SQL_SUCCESS)
AfxMessageBox("Excute Sucess!");
}
失败!
time表中只有一个字段datatime