为什么ExecuteNonQuery执行成功了返回1,但Access还是没有被更新?
按钮程序如下:
protected void Button1_Click(object sender, EventArgs e)
{
strSQL = "update config set grade_name=@GradeName,grade_year=@GradeYear,xuenian=@xuenian,xueqi=@xueqi,Dormitory=@Dormitory,xueke=@xueke,ke=@ke,";
strSQL += "stStatus=@stStatus,haveStPhoto=@haveStPhoto,zhidu=@zhidu";
OleDbParameter[] parameters = {
new OleDbParameter("@GradeName", OleDbType.VarChar,200),
new OleDbParameter("@GradeYear", OleDbType.VarChar,200),
new OleDbParameter("@xuenian", OleDbType.VarChar,10),
new OleDbParameter("@xueqi", OleDbType.VarChar,10),
new OleDbParameter("@Dormitory", OleDbType.VarChar,100),
new OleDbParameter("@xueke", OleDbType.VarChar,100),
new OleDbParameter("@ke", OleDbType.VarChar,255),
new OleDbParameter("@stStatus", OleDbType.VarChar,200),
new OleDbParameter("@haveStPhoto", OleDbType.Boolean,2),
new OleDbParameter("@zhidu", OleDbType.LongVarChar,5000),
};
parameters[0].Value = txbGradeName.Text;
parameters[1].Value = txbGradeYear.Text;
parameters[2].Value = ddlXuenian.SelectedValue;
parameters[3].Value = ddlXueqi.SelectedValue;
parameters[4].Value = txbDormitory.Text;
parameters[5].Value = txbXueke.Text;
parameters[6].Value = txbKe.Text;
parameters[7].Value = txbStStatus.Text;
if (rblStPhoto.SelectedValue == "True")
parameters[8].Value = true;
else
parameters[8].Value = false;
parameters[9].Value = Request.Form["content1"];
int cmdResult = GetExcuteNonQuery(strSQL, parameters);
if (cmdResult == 1)
MsgBox("修改成功!", "Config.aspx");
}
********************************************************************
GetExcuteNonQuery()的程序如下:
/// <summary>
/// 单向操作,主要用于(增加,删除,修改),返回受影响的行数
/// </summary>
/// <param name="cmdTxt">安全的sql语句(string.format)</param>
/// <returns></returns>
public static int GetExcuteNonQuery(string cmdTxt)
{
try
{
return GetExcuteNonQuery(cmdTxt, null);
}
finally
{
conn.Close();
}
}
/// <summary>
/// 带参数化的 主要用于(增加,删除,修改),返回受影响的行数
/// </summary>
/// <param name="cmdTxt"></param>
/// <param name="pars"></param>
/// <returns></returns>
public static int GetExcuteNonQuery(string cmdTxt, params OleDbParameter[] pars)
{
using (cmd = new OleDbCommand(cmdTxt, connectionstrings))
{
if (pars != null)
cmd.Parameters.AddRange(pars);
int i = cmd.ExecuteNonQuery();
conn.Close();
return i;
}
} ExecuteNonQuery? access
[解决办法]
你的update 语句不带where吗?