我用ADO的Execute执行插入语句插入一条记录后程序就停止运行,不知道为什么??
代码如下:
#import "c:\Program Files\Common Files\System\ADO\msado15.dll" \
no_namespace rename("EOF", "EndOfFile")
#include <stdio.h>
#include <icrsint.h>
extern"C"void datainsert(int a,float p1,float p2,float p3,float p4,float p5,float p6)
{
::CoInitialize(NULL);
try
{ char sql[41];
_variant_t RecordsAffected;
_ConnectionPtr m_pConnection;
m_pConnection.CreateInstance(_uuidof(Connection));
_RecordsetPtr m_pRecordset;
m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=二维有压渗流数据.mdb;","","",adModeUnknown);
m_pRecordset.CreateInstance(_uuidof(Recordset));
m_pRecordset->Open("SELECT * FROM 单刚矩阵存储",
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=二维有压渗流数据.mdb",
adOpenStatic, adLockUnspecified, adCmdText);
sprintf(sql,"INSERT INTO 单刚矩阵存储(单元号,K11,K12,K13,K22,K23,K33)VALUES(%d,%f,%f,%f,%f,%f,%f)",a,p1,p2,p3,p4,p5,p6);
m_pConnection->Execute(sql,&RecordsAffected,adCmdText);
}
catch (_com_error &e)
{
printf("Error:\n");
printf("Code = %08lx\n", e.Error());
printf("Meaning = %s\n", e.ErrorMessage());
printf("Source = %s\n", (LPCSTR) e.Source());
printf("Description = %s\n", (LPCSTR) e.Description());
}
::CoUninitialize();
} |