asp.net怎么老是提示 输入字符串的格式不正确,下面的这句代码有错误吗?

来源:百度知道 编辑:UC知道 时间:2024/06/30 15:52:07
int del = Convert.ToInt32(e.CommandArgument.ToString());
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
OleDbConnection con = DB.creatcon();
int del = Convert.ToInt32(e.CommandArgument.ToString());
if (e.CommandName == "del")
{
OleDbCommand cmd = new OleDbCommand("delete from Board where Bid="+del+"",con);
con.Open();

cmd.ExecuteNonQuery();
Response.Redirect("MasBoard.aspx");

}

e.CommandArgument.ToString()不是一个数字

肯定是字符串有问题
跟踪看一下那个e.CommandArgument.ToString()得到的是什么,要是有空格,先取掉空格:
e.CommandArgument.ToString().Trim();

int del = int.Parse(e.CommandArgument.ToString());

delete from Board where Bid='"+del+"'",con
少了单引号