ZRunners 2013-12-03 02:22 采纳率: 50%
浏览 3292
已采纳

VC++ mfc连接odbc数据库后,不能对数据库的记录更新(增删改),只能查寻是什么原因?

下面是一段插入的代码,不能插入,在第二个str.Format()时出现FROM子句出错。
我在执行查询时是成功的。
void CINPUT::OnTianjia()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
if(m_No.IsEmpty() || m_name.IsEmpty() || m_danj.IsEmpty() || m_count.IsEmpty())
{
MessageBox("信息不完整,请输入完整信息!");
return;
}
Cmyrecord a(db);
CString str;
str.Format("select * from ruku ");
if(a.Open(CRecordset::snapshot,str))
// MessageBox("success");

 if(a.GetRecordCount()<=0)
 {
     MessageBox("没有该商品的入库记录,添加新品!");
     return ;
 }

 Cmyrecord b(db);
 CString cstr;
 cstr.Format("select * form kucun");
 int pos = m_list1.GetItemCount();
 m_list1.InsertItem(pos,"");
 m_list1.SetItemText(pos,0,m_No);
 m_list1.SetItemText(pos,1,m_name);
 m_list1.SetItemText(pos,2,m_danj);
 m_list1.SetItemText(pos,3,m_count);
        MessageBox("success");
 str.Format("select * from kucun insert into kucun values('%s','%s','%s','%s')",m_No,m_name,m_danj,m_count);
 if(b.Open(CRecordset::snapshot,str))
     MessageBox("success");
m_No="";
m_name="";
m_danj="";
m_count="";
UpdateData(false);
 a.Close();
 b.Close(); 

}

  • 写回答

1条回答 默认 最新

  • wqshappy 2013-12-03 05:18
    关注

    "select * from kucun insert into kucun values('%s','%s','%s','%s')"
    这是什么sql语法呀 这个语法就不对

    insert into kucun values('%s','%s','%s','%s')"
    这样就行了 前面加个select * from kucun 有什么用?
    加上之后整个语句连语法都不对

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算