一个利用datagrid数据更新时数据类型转换错误!高分求救!
小弟在利用datagrid进行数据类型转换时错误!后台数据库为sqlserver2000
字段类型为char
SqlConnection conn= new SqlConnection("data source=SHIZHOUBO;initial catalog=communication;persist security info=False;user id=sa;workstation id=SHIZHOUBO;packet size=4096");
conn.Open();
string spid=((TextBox)e.Item.Cells[1].Controls[0]).Text;
string spname=((TextBox)e.Item.Cells[2].Controls[0]).Text
string spriname=((TextBox)e.Item.Cells[3].Controls[0]).Text;
string strust=((TextBox)e.Item.Cells[4].Controls[0]).Text;
string sqlstr="Update new_product Set pname="+spname+",priname="+spriname+",trust="+strust+" where pid='"+spid+"'";
SqlCommand ss= new SqlCommand(sqlstr,conn);
ss.ExecuteNonQuery();
newgrid.DataBind();
数据进行更新时一致在提示“列名”无效无法更新
如果要为 spname="778788";
...........
...........
类似这样的用数字字可以更新!没有问题,可是小弟在添加记录时用字符串没有错误呀!