SQL语句问题,这个问题困扰了两天了!
添加语句:
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;
}
}