每次程序运行至:m_pRecordset->Update();时出错,是末知错误,源程序如下:
try{
_RecordsetPtr m_pRecordset;
m_pRecordset.CreateInstance("ADODB.Recordset");
m_pRecordset->Open("fileinfo",
_variant_t((IDispatch*)m_pConnection,true),
adOpenKeyset,adLockOptimistic,adCmdTable); //添加文件到数据库
CString str = "M:\\3333.cut";
OpenFile(str);
char *pBuf = m_pFileBuf;
VARIANT varBLOB;
SAFEARRAY *psa;
SAFEARRAYBOUND rgsabound[1];
m_pRecordset->AddNew();
m_pRecordset->PutCollect("id",_variant_t("stu_1"));
m_pRecordset->PutCollect("name",_variant_t("stu_1"));
m_pRecordset->PutCollect("filename",_variant_t("3333"));
CString strCurTime;
CTime t = GetCurrentTime();
strCurTime.Format("%4d-%02d-%02d %02d:%02d:%02d", t.GetYear(),t.GetMonth(),t.GetDay(),t.GetHour(),t.GetMinute(),t.GetSecond());
m_pRecordset->PutCollect("addtime",_variant_t(strCurTime));
m_pRecordset->PutCollect("abstract",_variant_t("just a test"));
if(pBuf)
{
rgsabound[0].lLbound = 0;
rgsabound[0].cElements = m_nFileLength;
psa = SafeArrayCreate(VT_UI1, 1, rgsabound);///创建SAFEARRAY对象
for (long i = 0; i < m_nFileLength; i++)
SafeArrayPutElement (psa, &i, pBuf++);///将pBuf指向的二进制数据保存到SAFEARRAY对象psa中
varBLOB.vt = VT_ARRAY | VT_UI1; ///将varBLOB的类型设置为BYTE类型的数组
varBLOB.parray = psa; ///为varBLOB变量赋值
m_pRecordset->GetFields()->GetItem("file")->AppendChunk(varBLOB);
}
m_pRecordset->Update();
m_pRecordset->Close();
}
catch(_com_error e)///捕捉异常
{
CString errormessage;
errormessage.Format("连接数据库失败!\r\n错误信息:%s",e.ErrorMessage());
AfxMessageBox(errormessage);///显示错误信息
return ;
}
try{
_RecordsetPtr m_pRecordset;
m_pRecordset.CreateInstance("ADODB.Recordset");
m_pRecordset->Open("fileinfo",
_variant_t((IDispatch*)m_pConnection,true),
adOpenKeyset,adLockOptimistic,adCmdTable); //添加文件到数据库
CString str = "M:\\3333.cut";
OpenFile(str);
char *pBuf = m_pFileBuf;
VARIANT varBLOB;
SAFEARRAY *psa;
SAFEARRAYBOUND rgsabound[1];
m_pRecordset->AddNew();
m_pRecordset->PutCollect("id",_variant_t("stu_1"));
m_pRecordset->PutCollect("name",_variant_t("stu_1"));
m_pRecordset->PutCollect("filename",_variant_t("3333"));
CString strCurTime;
CTime t = GetCurrentTime();
strCurTime.Format("%4d-%02d-%02d %02d:%02d:%02d", t.GetYear(),t.GetMonth(),t.GetDay(),t.GetHour(),t.GetMinute(),t.GetSecond());
m_pRecordset->PutCollect("addtime",_variant_t(strCurTime));
m_pRecordset->PutCollect("abstract",_variant_t("just a test"));
if(pBuf)
{
rgsabound[0].lLbound = 0;
rgsabound[0].cElements = m_nFileLength;
psa = SafeArrayCreate(VT_UI1, 1, rgsabound);///创建SAFEARRAY对象
for (long i = 0; i < m_nFileLength; i++)
SafeArrayPutElement (psa, &i, pBuf++);///将pBuf指向的二进制数据保存到SAFEARRAY对象psa中
varBLOB.vt = VT_ARRAY | VT_UI1; ///将varBLOB的类型设置为BYTE类型的数组
varBLOB.parray = psa; ///为varBLOB变量赋值
m_pRecordset->GetFields()->GetItem("file")->AppendChunk(varBLOB);
}
m_pRecordset->Update();
m_pRecordset->Close();
}
catch(_com_error e)///捕捉异常
{
CString errormessage;
errormessage.Format("连接数据库失败!\r\n错误信息:%s",e.ErrorMessage());
AfxMessageBox(errormessage);///显示错误信息
return ;
}
_variant_t((IDispatch*)m_pConnection,true),
adOpenKeyset,adLockOptimistic,adCmdTable);
==这里"fileinfo"是什么东西?
我第一次写这种程序
m_pRecordset->Open("select * from fileinfo",
_variant_t((IDispatch*)m_pConnection,true),
adOpenKeyset,adLockOptimistic,adCmdTable);
出现了这样的错误
错误信息:IDispatch error #3092"
...
m_pRecordset->MoveFirst();
m_pRecordset->Update();
如果增加了m_pRecordset->MoveFirst();
那就在这句就出错了,呵呵
您好,我调试过了
是在m_pRecordset->Update();这句
跳到catch去的
m_nFileLength 值对吗,检查一下又没有溢出
表的主键是另一个自动生成的recordid,现在我数据库里没有任何东西,是试着第一次向数据库中写东西
应该不会是m_nFileLength的问题,才5万多一点
请问您有邮箱吗
要不我把程序和数据库发给您,您帮我看一下,可以吗
但我没有数据库啊。
建议先输入一个值,看看update会不会出错
不会吧,呵呵
我的库是用access建的,如果您的机器上有access就应该可以吧
已经将程序发到您的邮箱,请查收一下
我又仔细调了一下程序
m_pRecordset->AddNew();
m_pRecordset->PutCollect("id",_variant_t("stu_1"));
m_pRecordset->Update();
如果我的程序只有这一句,在update的时候都会出错
我运行您的程序在本地写就没有问题,但是写到服务器上就出错了
服务器上的数据库是用access的表导入的
哈哈,问题终于解决了,程序没有任何问题
是access导入sql server的时候出问题了,导致了数据库的fileinfo那张表不正常了,呵呵
多谢您的热心帮助,也谢谢所有在这里热心帮忙的朋友:)