我现在写了一个access的查询语句,
//修改资料
public static int UpdateById(News ne)
{
string sql = "update News set Title='" + ne.Title + "',entitle='" + ne.Entitle + "',encontent='" + ne.Encontent + "',jptitle='" + ne.Jptitle + "',jpcontent='" + ne.Jpcontent + "',Content='" + ne.Content + "',BigClassName='" + ne.BigClassName + "',SmallClassName='" + ne.SmallClassName + "',User='" + ne.User + "',Infotime='"+ne.Infotime+"' where id=" + ne.ID + " ";
return DBHelper.ExecuteCommand(sql);
}我进行调试,把生成的sql语句写进数据库中运行没问题,可是在代码中运行到 return DBHelper.ExecuteCommand(sql);按F11进度DBheper中,运行 public static int ExecuteCommand(string safeSql)
{ OleDbConnection conn = new OleDbConnection(connectionString);
OleDbCommand cmd = new OleDbCommand(); try
{
PrepareCommand(cmd, conn, CommandType.Text, safeSql, null);
int result = cmd.ExecuteNonQuery();
return result;
}
catch (Exception e)
{
return 0;
}
finally
{
cmd.Dispose();
conn.Close();
conn.Dispose();
}
}
当运行到int result = cmd.ExecuteNonQuery();后,直接跳到 catch (Exception e)中就提示说update语法错误,这是怎么回事啊??
//修改资料
public static int UpdateById(News ne)
{
string sql = "update News set Title='" + ne.Title + "',entitle='" + ne.Entitle + "',encontent='" + ne.Encontent + "',jptitle='" + ne.Jptitle + "',jpcontent='" + ne.Jpcontent + "',Content='" + ne.Content + "',BigClassName='" + ne.BigClassName + "',SmallClassName='" + ne.SmallClassName + "',User='" + ne.User + "',Infotime='"+ne.Infotime+"' where id=" + ne.ID + " ";
return DBHelper.ExecuteCommand(sql);
}我进行调试,把生成的sql语句写进数据库中运行没问题,可是在代码中运行到 return DBHelper.ExecuteCommand(sql);按F11进度DBheper中,运行 public static int ExecuteCommand(string safeSql)
{ OleDbConnection conn = new OleDbConnection(connectionString);
OleDbCommand cmd = new OleDbCommand(); try
{
PrepareCommand(cmd, conn, CommandType.Text, safeSql, null);
int result = cmd.ExecuteNonQuery();
return result;
}
catch (Exception e)
{
return 0;
}
finally
{
cmd.Dispose();
conn.Close();
conn.Dispose();
}
}
当运行到int result = cmd.ExecuteNonQuery();后,直接跳到 catch (Exception e)中就提示说update语法错误,这是怎么回事啊??
要是认为高手可以加我QQ82626948,谢谢,远程调试一下啊
Infotime=#"+ne.Infotime+"#
strSql.Append("update Types set ");
strSql.Append("IsOutput=@IsOutput,");
strSql.Append("SortValue=@SortValue,");
strSql.Append("TypeName=@TypeName");
strSql.Append(" where TypeID=@TypeID ");
OleDbParameter[] parameters = {
new OleDbParameter("@IsOutput", OleDbType.Boolean,2),
new OleDbParameter("@SortValue", OleDbType.Integer,4),
new OleDbParameter("@TypeName", OleDbType.VarChar,250),
new OleDbParameter("@TypeID", OleDbType.Integer,4)};
parameters[0].Value = model.IsOutput;
parameters[1].Value = model.SortValue;
parameters[2].Value = model.TypeName;
parameters[3].Value = model.TypeID;
return DbHelperOleDb.ExecuteSql(strSql.ToString(), parameters) > 0;