当前位置: 代码迷 >> ASP.NET >> 大家帮小弟我看看哪里写错了
  详细解决方案

大家帮小弟我看看哪里写错了

热度:3570   发布时间:2013-02-26 00:00:00.0
大家帮我看看哪里写错了
private   void   DataGrid1_UpdateCommand(object   source,   System.Web.UI.WebControls.DataGridCommandEventArgs   e)
{
string   GoodName=((TextBox)e.Item.Cells[1].Controls[0]).Text;
string   Unit=((TextBox)e.Item.Cells[2].Controls[0]).Text;
string   Price=((TextBox)e.Item.Cells[3].Controls[0]).Text;
DateTime   AddDate=Convert.ToDateTime(((TextBox)e.Item.Cells[5].Controls[0]).Text);
int     GoodID=(int)DataGrid1.DataKeys[(int)e.Item.ItemIndex];
SqlConnection   conn=new   SqlConnection   ( "server=.;uid=sa;pwd=;database=B2CDB ");
string   com= "update   Goods   set   GoodName= ' "+GoodName+ " 'Unit= ' "+Unit+ " ',Price= ' "+Price+ " ',AddDate= ' "+AddDate+ " '   where   GoodID= "+GoodID;
SqlCommand   cmd=new   SqlCommand(com,conn);
conn.Open();
try
{
cmd.ExecuteNonQuery();
DataGrid1.EditItemIndex=-1;
GridBind();
}
catch(Exception   err)
{
Response.Write(err.ToString());
}
finally
{
conn.Close();
}
}
大家帮我看看AddDate字段更新说指定的转换无效,哪写错了

------解决方案--------------------------------------------------------
DateTime AddDate=Convert.ToDateTime(((TextBox)e.Item.Cells[5].Controls[0]).Text);

验证((TextBox)e.Item.Cells[5].Controls[0]).Text这个字符串是否是日期型的,可以单步调试查看这个值
  相关解决方案