编写更新查询时遇到问题 [英] Having trouble while writing update query

查看:125
本文介绍了编写更新查询时遇到问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



  string  str1 =   更新Login_Table set p_word = + TextBox2.Text +   where user_name =' + Session [  name]。ToString ()+  '; 



cmd = new SqlCommand();

cmd.CommandText = str1;

cmd.Connection = db.con;

cmd .ExecuteNonQuery();





我收到的错误就是列名无效。我不善于编写查询。

解决方案

是你的密码列列是数字??

可能不是。所以它应该是p_word ='+ TextBox2.Text +'。你必须在quoate中给出密码,因为它是一个字符串.copy并享受:

 < span class =code-keyword> string  str1 =   update Login_Table set p_word =' + TextBox2.Text +  'where user_name =' + Session [  name]。ToString()+  '; 



string str1 = "update Login_Table set p_word=" + TextBox2.Text + " where user_name='" + Session["name"].ToString() + "'";


cmd = new SqlCommand();
cmd.CommandText = str1;
cmd.Connection = db.con;
cmd.ExecuteNonQuery();


I am getting error like , invalid column name. I am bad at writing queries.

解决方案

is your password column column is numeric??
probably not. so it should be p_word='" + TextBox2.Text + "' .you have to give password in quoate as it is a string .copy and enjoy :

string str1 = "update Login_Table set p_word='" + TextBox2.Text + "' where user_name='" + Session["name"].ToString() + "'";


这篇关于编写更新查询时遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆