新手提问.关于输入方法名称
1 protected void DataGrid1_UpdateCommand(object source, DataGridCommandEventArgs e)
2 {
3 SqlConnection myconnection = conn();
4 string updatestr = " ";
5 updatestr += "bookid='"((TextBox)e.Item.Cells[2].Controls[0]).text+ "'";
6 updatestr += ",bookname='"((TextBox)e.Item.Cells[3].Controls[0]).text + "'";
7 updatestr += ",content='"((TextBox)e.Item.Cells[4].Controls[0]).text + "'";
8 updatestr += ",author='"((TextBox)e.Item.Cells[5].Controls[0]).text + "'";
9 updatestr += ",publisher='"((TextBox)e.Item.Cells[6].Controls[0]).text + "'";
10 updatestr += ",price='"((TextBox)e.Item.Cells[7].Controls[0]).text + "'";
string updatecmd = "update book_information set " + updatestr + "where bookid='" + DataGrid1.DataKeys[e.Item.ItemIndex] + "'";
SqlCommand mycommand = new SqlCommand(updatecmd, myconnection);
try
{
myconnection.Open();
mycommand.ExecuteNonQuery();
DataGrid1.EditItemIndex = -1;
}
catch
{
Response.Write("<script>alert('更新失败')</script>");
}
finally
{
myconnection.Close();
}
binddata();
}
运行后提示6-10行 应该输入方法名称.不懂什么意思
------解决方案--------------------updatestr += "bookid='"((TextBox)e.Item.Cells[2].Controls[0]).text+ "'";
应该是updatestr += "bookid='"+((TextBox)e.Item.Cells[2].Controls[0]).text+ "'";
下面一样。
------解决方案--------------------不明白你為什麽這樣寫,直接在Code里寫sql的做法不推薦
C# code
string updatecmd = "update book_information set bookid='" + ((TextBox)e.Item.Cells[2].Controls[0]).text+
"',bookname='" + ((TextBox)e.Item.Cells[3].Controls[0]).text +
"' ,content='" + ((TextBox)e.Item.Cells[4].Controls[0]).text +
"' ,author='" + ((TextBox)e.Item.Cells[5].Controls[0]).text +
"', publisher='" + ((TextBox)e.Item.Cells[6].Controls[0]).text +
"',price='" + ((TextBox)e.Item.Cells[7].Controls[0]).text +
"' where bookid='" + DataGrid1.DataKeys[e.Item.ItemIndex] + "'";