首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

新手提问.关于输入方法名称,该如何处理

2012-03-03 
新手提问.关于输入方法名称1 protected void DataGrid1_UpdateCommand(object source, DataGridCommandEve

新手提问.关于输入方法名称
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] + "'"; 

热点排行