SQL语句问题,这个问题困扰了两天了!

liufen137 2010-03-25 12:17:20
添加语句:
sql="insert into Rules (车辆类型,通道,特征名,特征值,逻辑关系,说明) values(strVehicle,strChannel,strPropertyName,strPropertyValue,strLogicalRelation,strRuleNote)";

if(!conn.ExecuteSQL(sql))//执行插入操作
{//操作失败
MessageBox("操作失败!");//提示失败
conn.ExitConnect();//关闭数据库连接//
return;//返回
}
MessageBox("添加成功!");
其中:CString strVehicle;//通道
CString strChannel;
CString strPropertyName;//特征名
CString strPropertyValue;//特征值
CString strLogicalRelation;//逻辑关系
CString strRuleNote;

删除语句:strsql.Format("delete from Rules where 规则号=%d",m_row);
m_doConn.ExecuteSQL((_bstr_t)strsql);
sql.Format("update Rules set 规则号=(规则号-1) where规则号>%d,m_row");
m_doConn.ExecuteSQL((_bstr_t)sql);

修改语句:
CString sql;
sql.Format("Update Rules set 车辆类型 =strVehicle,通道=strChannel,特征名=strPropertyName,特征值=strPropertyValue,逻辑关系=strLogicalRelation,说明=strRuleNote where 规则号=m_row");
if(!m_AdoConn.ExecuteSQL((_bstr_t)sql))//执行插入操作
{//操作失败
MessageBox("操作失败!");//提示失败
m_AdoConn.ExitConnect();//关闭数据库连接//
return;//返回
}
MessageBox("添加成功!");
其中:CString strVehicle;//通道
CString strChannel;
CString strPropertyName;//特征名
CString strPropertyValue;//特征值
CString strLogicalRelation;//逻辑关系
CString strRuleNote;
为什么运行后这三条语句最后都出现“数据库SQL语句执行失败”呢?语句本身有没有错误啊?

附:
BOOL ADOConn::ExecuteSQL(_bstr_t bstrSQL)
{
_ConnectionPtr m_pConnection;
try
{
// 是否已经连接数据库
if(m_pConnection == NULL)
OnInitADOConn();
m_pConnection->Execute(bstrSQL,NULL,adCmdText);
return true;
}
catch(_com_error e)
{
AfxMessageBox("数据库SQL语句执行失败!");
return false;
}
}
...全文
164 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
--小F-- 2010-03-25
  • 打赏
  • 举报
回复
sql="insert into 
Rules (车辆类型,通道,特征名,特征值,逻辑关系,说明)
values('" + strVehicle + "','" + strChannel+ "','" + strPropertyName + "','" + strPropertyValue + "','" + strLogicalRelation + "','" + strRuleNote + "')";
octwind 2010-03-25
  • 打赏
  • 举报
回复

sql="insert into Rules (车辆类型,通道,特征名,特征值,逻辑关系,说明) values('" + strVehicle + "','" + strChannel+ "','" + strPropertyName + "','" + strPropertyValue + "','" + strLogicalRelation + "','" + strRuleNote + "')";

sxiaohui8709253 2010-03-25
  • 打赏
  • 举报
回复
路过 。。。。。
ChinaJiaBing 2010-03-25
  • 打赏
  • 举报
回复
sql="insert into Rules (车辆类型,通道,特征名,特征值,逻辑关系,说明) values(strVehicle,strChannel,strPropertyName,strPropertyValue,strLogicalRelation,strRuleNote)";

----try

sql="insert into Rules (车辆类型,通道,特征名,特征值,逻辑关系,说明) values('strVehicle',
'strChannel','strPropertyName','strPropertyValue','strLogicalRelation','strRuleNote')";

永生天地 2010-03-25
  • 打赏
  • 举报
回复
CString sql;
sql.Format("Update Rules set 车辆类型 =strVehicle,通道=strChannel,特征名=strPropertyName,特征值=strPropertyValue,逻辑关系=strLogicalRelation,说明=strRuleNote where 规则号=m_row");

这些不需要用s%来标识吗
happy664618843 2010-03-25
  • 打赏
  • 举报
回复
调试下 print
starseeker7 2010-03-25
  • 打赏
  • 举报
回复
把语句print出来,手动拷贝到SQL里去运行看OK不
这里说用处不大
liangxupan 2010-03-25
  • 打赏
  • 举报
回复
sql=String.Formate("insert into
Rules (车辆类型,通道,特征名,特征值,逻辑关系,说明)
values('{0}’,'{1}','{2}','{3}','{4}','{5}'),strVehicle,strChannel,strPropertyName,strPropertyValue ,strLogicalRelation ,strRuleNote);
水中影子 2010-03-25
  • 打赏
  • 举报
回复
把拼接的SQL打印看看
liufen137 2010-03-25
  • 打赏
  • 举报
回复
问题依旧没有解决。
Stone19840824 2010-03-25
  • 打赏
  • 举报
回复
调试一下 将生成的语句输出来看看呢
qiqi860819 2010-03-25
  • 打赏
  • 举报
回复
拼接字符串的问题

34,576

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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