修改数据库Name字段,首先我在修改页的Page_Load加载事件里先查询出来,代码如下:
SqlCommand cmd = new SqlCommand(select * from Table, conn);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds);
this.txtMingcheng.Text = ds.Tables[0].Rows[0]["Name"].ToString();//查询结果例如是:123,然后放到文本框里了。
我现在要把我查询出来的结果修改,代码如下:
string sqlstr = "update Table set Name="+this.txtMingcheng.Text+";
SqlCommand cmd = new SqlCommand(sqlstr,conn);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds);问题出来了,当我在文本框里输入456的时候点提交,然后数据还是123?这咋办啊?