c# update修改sql内信息

来源:百度知道 编辑:UC知道 时间:2024/06/15 21:52:26
string connStr = "data source =ylkj-b2591s1ij2;initial catalog=goods;uid=sa;Password=111";
SqlConnection con = new SqlConnection(connStr);
con.Open();
string note1 = TextBox1.Text.
string sql = "update goods set goods_name=" + note1 + "";
SqlCommand cmd = new SqlCommand(sql, con);
cmd.ExecuteNonQuery();
执行说"列名 'note1' 无效。"
怎么改呢,就是将在textbox中输入信息修改后在存入数据库
我是在另一个aspx中执行了
<a href="Default3.aspx?id=<%# DataBinder.Eval(Container.DataItem, "id") %>">打开</a>
进入的,要求修改当前的id的数据,直接执行可以修改了,但是调用过来就不行了,哪个高手帮帮忙哈,update后的where该怎么写啊

string sql = "update goods set goods_name='" + note1 + "'";

note1 前后单引号

string sql = "update goods set goods_name=‘" + note1 + "' where id='"+Request.QueryString["id"].toString()+"'";

string sql = "update goods set goods_name='" + note1 + "'";

字符型 需要单引号

是不是其他地方出错了 存不进数据库? 我也不知道了 代码到没写错啊

给你个例子
''update student set name='''+this.TextBox2.Text+'''where id=''+this.TextBox1.Text+'''';