我想做一个windows Form程序,在界面上的文本框输入一个名称,点击查询按钮,可以使用这个名称作为查询条件在数据库中进行查询,但是我写的代码不对,请大家帮忙改正一下,调试的时候总显示textbox。text=null,下面是我的代码:
TextBox textbox1=new TextBox();
string text=textbox1.Text;
string strsql="select station_name from station where station_name=text";
TextBox textbox1=new TextBox();
string text=textbox1.Text;
string strsql="select station_name from station where station_name=text";
要是是数字型的话
string strsql="select station_name from station where station_name="+text+"";就可以了
string text=textbox1.Text;
string strsql="select station_name from station where station_name=\"" + text +"\""; //<---
TextBox textbox1=new TextBox();
textbox.text="ss";
this.controls.add(textbox1);
string text=textbox1.Text;
string text=textbox1.Text; -->textbox1还没有赋值
1.声明后应该添加到controls 具体this.controls.add(textbox1);
2.string strsql="select station_name from station where station_name=text";应该写成
string strsql="select station_name from station where station_name="+text+"";
都是手写的,你不能直接拷,注意大写吧!
字符型这样就可以了啊!
string strsql="select station_name from station where station_name='"+text+"'";
string text=textbox1.Text;
string strsql="select station_name from station where station_name=\"" + text +"\""; // <---
sql语句拼错了啊!
TextBox textbox1=new TextBox();
string text=textbox1.Text; string strsql="select station_name from station where station_name=‘+“text”+’";
2.放一个Button控件在窗体上,双击这个Button,在后台的Click事件中写如下代码string text = txtStationName.Text;
string strsql = "select station_name from station where station_name='" + text + "'";
经过以上步骤后,当你在文本框中输入后,点击按钮就可以在后台代码中取得这个文本框的信息了。
string strsql="select station_name from station where station_name='"+text+"'"