本文介绍了错误:输入字符串格式不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在这里,我尝试编写用于从gridview删除行的代码,但是当我单击Delete按钮时,出现错误:输入字符串的格式不正确.
这是我的删除按钮代码.
Hi,
Here I have tried to write a code for deleting a row from gridview but when I clicked on delete button, I get an error: input string is not in correct format.
Here is my delete button code.
protected void gridItem_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["connectionstring"].ToString());
SqlCommand sqlDelete = new SqlCommand("delete from product_detail where Product_Id=@Product_Id", con);
sqlDelete.Parameters.Add("@Product_Id", SqlDbType.Int).Value = Convert.ToInt32(gridItem.Rows[e.RowIndex].Cells[1].Text.Trim());
sqlDelete.Connection = con;
con.Open();
sqlDelete.ExecuteNonQuery();
con.Dispose();
con.Close();
fillgrid();
gridItem.DataBind();
}
请告诉我这段代码在哪里?
Please tell me where am I wrong in this code?
推荐答案
sqlDelete.Parameters.Add("@Product_Id", SqlDbType.Int).Value = Convert.ToInt32(gridItem.Rows[e.RowIndex].Cells[1].Text.Trim());
您是否检查过Cell
值可转换为Integer
?
或请指定出现错误的行,否则我们将无法承担.
如果有帮助,请 投票 和 接受答案 .
Have you checked that the Cell
value is convertible to Integer
?
or Please specify the line where you are getting error otherwise we can''t assume.
Please vote and Accept Answer if it Helped.
int prod_id = Convert.ToInt32(gridItem.Rows[e.RowIndex].Cells[1].Text.Trim().ToString());
sqlDelete.Parameters.Add("@Product_Id", prod_id);
还要在sqlCommand中放置一个空格
Also put a space in the sqlCommand
SqlCommand sqlDelete = new SqlCommand("delete from product_detail where Product_Id = @Product_Id", con);
这篇关于错误:输入字符串格式不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!