部分源代码如下: StrSql = "update test set Name='" + Session["Name"].ToString().Trim() + "',STime='" + DateTime.Now.ToShortDateString().Trim() + "' where ID='" + TID + "'"; Result = TTSTool.SqlCMD(StrSql, strVBConn).ToString().Trim();SqlCMD自定义的函数 public string SqlCMD(string StrSql,string strDBConn) { //StrSql:执行语句 //strDBConn:数据库驱动 string ReturnValue = ""; try { SqlConnection DBConn = new SqlConnection(strDBConn); DBConn.Open(); SqlCommand DBCMD = new SqlCommand(StrSql, DBConn); DBCMD.ExecuteNonQuery(); DBConn.Close(); ReturnValue = "1"; } catch (Exception ex) { ReturnValue = "数据操作失败! - " + ex.Message.ToString().Trim(); } return ReturnValue; }
有可能是 ntex的数据有 ' 等字符 改变了sql语句的 合法性 所以执行出错
既然数据库服务器与应该服务器在一台机器上,不妨将STime=sysdate
StrSql = "update test set Name='" + Session["Name"].ToString().Trim() + "',STime=sysdate where ID='" + TID + "'"; 如果STime为字符类型需改为: StrSql = "update test set Name='" + Session["Name"].ToString().Trim() + "',STime=to_char(sysdate,'yyyy-mm-dd') where ID='" + TID + "'"; 如还有错误,将错误原因也贴出来。
StrSql = "update test set Name='" + Session["Name"].ToString().Trim() + "',STime='" + DateTime.Now.ToShortDateString().Trim() + "' where ID='" + TID + "'";
Result = TTSTool.SqlCMD(StrSql, strVBConn).ToString().Trim();SqlCMD自定义的函数
public string SqlCMD(string StrSql,string strDBConn)
{
//StrSql:执行语句
//strDBConn:数据库驱动
string ReturnValue = "";
try
{
SqlConnection DBConn = new SqlConnection(strDBConn);
DBConn.Open();
SqlCommand DBCMD = new SqlCommand(StrSql, DBConn);
DBCMD.ExecuteNonQuery();
DBConn.Close();
ReturnValue = "1";
}
catch (Exception ex)
{
ReturnValue = "数据操作失败! - " + ex.Message.ToString().Trim();
}
return ReturnValue;
}
"',STime=sysdate where ID='" + TID + "'";
如果STime为字符类型需改为:
StrSql = "update test set Name='" + Session["Name"].ToString().Trim() +
"',STime=to_char(sysdate,'yyyy-mm-dd') where ID='" + TID + "'"; 如还有错误,将错误原因也贴出来。