IDispatch error #3092

tianqing52 2009-03-02 03:24:42
在用MFC 结合ADO进行数据库编程时,最后显示信息时出现IDispatch error #3092 ,怎么解决啊,高手帮帮忙。
select * from info where 姓名=%s,strname
...全文
4862 20 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
hhxdtnbd 2012-09-12
  • 打赏
  • 举报
回复
void CDBConnect::OnWriteDB(CString strPinyin,CString strWenzi)
{
CString strSQL;
strSQL.Format("Insert into ziku(pinyin,wenzi)values(\'%s\',\'%s\')",strPinyin,strWenzi);


try
{
m_ptReco.CreateInstance(__uuidof(Recordset));
m_ptReco=m_ptConn->Execute(_bstr_t(strSQL),NULL,adCmdText);
m_ptReco.Release();
m_ptConn.Release();
}
catch(_com_error error)
{
CString str;
str.Format("%s",error.ErrorMessage());
AfxMessageBox(str);
}
}
在m_ptReco=m_ptConn->Execute(_bstr_t(strSQL),NULL,adCmdText);中同样出现这个问题
zjll_ 2011-11-24
  • 打赏
  • 举报
回复
在采用ADO访问ACCESS数据库的时候,出现IDispatch error #3092错误的原因之一是在SQL语句中使用了保留关键字。

比如:如果表的名称为User 则会出现该错误。

另外,今天发现,若字段为value时也会出现上述错误:

!!!!!!!!大哥哥,你可能在SQL语句中使用了保留关键字,我就碰到过这种情况,把我脑袋都抓破了,上网查了才知道!嗨

http://hi.baidu.com/photopad/blog/item/a144f5a139856e8c47106484.html

xiaoxiao390 2011-03-05
  • 打赏
  • 举报
回复
请问你是怎么解决的啊??
只是空想家 2011-03-03
  • 打赏
  • 举报
回复
问题解决了
只是空想家 2011-02-22
  • 打赏
  • 举报
回复
希望高人帮忙解决一下啊 不胜感激
只是空想家 2011-02-22
  • 打赏
  • 举报
回复
我也遇到了
strSQL.Format("Update Material Set Material.MaterialID='s',Material.Name='s',Material.SumNumber=s,Material.Inventory=s,\
Material.Locate='%s',Material.Type='%s',Material.Press='%s',Material.Author='%s',\
Material.Price='%s',Material.StorageTime=#%s# where Material.MaterialID='%s",\
m_ID,m_name,m_sunNum,m_inventory,m_location,m_type,m_press,m_author,m_price,\
strDateTime,m_ID);语句好像是对的
m_adoConDel.ExecuteSQL((_bstr_t)strSQL);//此处有问题

BOOL ADOConn::ExecuteSQL(_bstr_t bstrSQL)
{

try
{
if(!m_pConnection->State)
OnInitADOConn();
m_pConnection->Execute(bstrSQL,NULL,adCmdText);
return true;
}
catch(_com_error e)
{
AfxMessageBox(e.ErrorMessage());
return false;
}
}
不听不看不说 2010-11-15
  • 打赏
  • 举报
回复
我之前遇到这个错误时,是因为我的查询语句中包含了保留字
dahai1988051 2010-08-24
  • 打赏
  • 举报
回复
我也遇到了这个错误,亟待解决
Ai君臣 2010-07-31
  • 打赏
  • 举报
回复
没有解决吗 高手们请教啊
wdc889 2010-02-03
  • 打赏
  • 举报
回复
try
{
rst->raw_Close();
rst->Open("select * from fifnum",conn.GetInterfacePtr(),adOpenDynamic, adLockPessimistic,adCmdText);
count=rst->GetRecordCount();
rst->Close();
rst->Open("select * from fifnum",conn.GetInterfacePtr(),adOpenStatic,adLockOptimistic,adCmdText);//打开就记录集
hnayx 2009-12-20
  • 打赏
  • 举报
回复
等待解决……
ivension 2009-12-01
  • 打赏
  • 举报
回复
我的程序代码也发生了这样的错误。
huiqq0016 2009-03-17
  • 打赏
  • 举报
回复
我程序代码如下发生了IDispatch error #3092
bool CFifNumDlg::IsRepeated(int board[][4])
{

_RecordsetPtr rst1;
CString sql="slect * from fifnum where ";
CString sql1,sql2,sql3,sql4;
rst1=rst;
int count;
sql1.Format("i0=%d and i1=%d and i2=%d and i3=%d and ",board[0][0],board[0][1],board[0][2],board[0][3]);
sql2.Format("i4=%d and i5=%d and i6=%d and i7=%d and ",board[1][0],board[1][1],board[1][2],board[1][3]);
sql3.Format("i8=%d and i9=%d and i10=%d and i11=%d and ",board[2][0],board[2][1],board[2][2],board[2][3]);
sql4.Format("i12=%d and i13=%d and i14=%d and i15=%d ",board[3][0],board[3][1],board[3][2],board[3][3]);
sql+=sql1;
sql+=sql2;
sql+=sql3;
sql+=sql4;
try
{
rst->raw_Close();
rst->Open((_bstr_t)sql,conn.GetInterfacePtr(),adOpenDynamic, adLockPessimistic,adCmdText);
count=rst->GetRecordCount();
rst->Close();
rst->Open("select * from fifnum",conn.GetInterfacePtr(),adOpenStatic,adLockOptimistic,adCmdText);//打开就记录集
if(count>0)
return true;
else
return false;
}
catch(_com_error &e)
{
AfxMessageBox(e.ErrorMessage(),0,0);
}
}


huiqq0016 2009-03-17
  • 打赏
  • 举报
回复
我程序代码如下也发生了IDispatch error #3092
bool CFifNumDlg::IsRepeated(int board[][4])
{

_RecordsetPtr rst1;
CString sql="slect * from fifnum where ";
CString sql1,sql2,sql3,sql4;
rst1=rst;
int count;
sql1.Format("i0=%d and i1=%d and i2=%d and i3=%d and ",board[0][0],board[0][1],board[0][2],board[0][3]);
sql2.Format("i4=%d and i5=%d and i6=%d and i7=%d and ",board[1][0],board[1][1],board[1][2],board[1][3]);
sql3.Format("i8=%d and i9=%d and i10=%d and i11=%d and ",board[2][0],board[2][1],board[2][2],board[2][3]);
sql4.Format("i12=%d and i13=%d and i14=%d and i15=%d ",board[3][0],board[3][1],board[3][2],board[3][3]);
sql+=sql1;
sql+=sql2;
sql+=sql3;
sql+=sql4;
try
{
rst->raw_Close();
rst->Open((_bstr_t)sql,conn.GetInterfacePtr(),adOpenDynamic, adLockPessimistic,adCmdText);
count=rst->GetRecordCount();
rst->Close();
rst->Open("select * from fifnum",conn.GetInterfacePtr(),adOpenStatic,adLockOptimistic,adCmdText);//打开就记录集
if(count>0)
return true;
else
return false;
}
catch(_com_error &e)
{

AfxMessageBox(e.ErrorMessage(),0,0);
}
}
tianqing52 2009-03-03
  • 打赏
  • 举报
回复
引起来还是报同样的错,怎么办呢?
zaodt 2009-03-02
  • 打赏
  • 举报
回复

一般来说,SQL 语句中的字符串常量需要用【单引号】括起来,所以:

CString str;
str.Format("select * from info where 姓名='%s'",strname)
MicrosoftWindow 2009-03-02
  • 打赏
  • 举报
回复
老大 语句错了select * from info where 姓名=‘%s’,strname
shakaqrj 2009-03-02
  • 打赏
  • 举报
回复
用_com_error的 Description()方法
mmcanyu 2009-03-02
  • 打赏
  • 举报
回复
把SQL语句拿去查询分析器运行一次啊
oyljerry 2009-03-02
  • 打赏
  • 举报
回复
try
{
//your code
}
catch(...)
{}

捕获一下异常

4,018

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 数据库
社区管理员
  • 数据库
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧