我想做一个windows Form程序,在界面上的文本框输入一个名称,点击查询按钮,可以使用这个名称作为查询条件在数据库中进行查询,但是我写的代码不对,请大家帮忙改正一下,调试的时候总显示textbox。text=null,下面是我的代码:
            TextBox textbox1=new TextBox();
            string text=textbox1.Text;
            string strsql="select station_name from station where station_name=text";

解决方案 »

  1.   

    string strsql="select station_name from station where station_name='"+text+"'";
    要是是数字型的话
    string strsql="select station_name from station where station_name="+text+"";就可以了
      

  2.   

                //TextBox textbox1=new TextBox(); 不用这行
                string text=textbox1.Text; 
                string strsql="select station_name from station where station_name=\"" + text +"\"";    //<---
      

  3.   

    你的TEXT是动态生成的啊!
     TextBox textbox1=new TextBox(); 
    textbox.text="ss";
    this.controls.add(textbox1);
                string text=textbox1.Text; 
      

  4.   

              TextBox textbox1=new TextBox(); 
                string text=textbox1.Text;   -->textbox1还没有赋值
      

  5.   

    this.controls.add(textbox1); 这句话不行,需要添加命名空间么?错误显示:“Public_Transport_Inquiry_System.Form2”并不包含“controls”的定义
      

  6.   

    两个错误 
    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+"";
      

  7.   

    string strSql = "select * from tableName where name = " + textbox1.Text.Tostring ();
      

  8.   

    this.Controls.Add(textbox1); 
    都是手写的,你不能直接拷,注意大写吧!
    字符型这样就可以了啊!
    string strsql="select station_name from station where station_name='"+text+"'"; 
      

  9.   

    //TextBox textbox1=new TextBox(); 不用这行 
                string text=textbox1.Text;  
                string strsql="select station_name from station where station_name=\"" + text +"\"";    // <---
      

  10.   


    sql语句拼错了啊!
    TextBox textbox1=new TextBox(); 
    string text=textbox1.Text; string strsql="select station_name from station where station_name=‘+“text”+’";
      

  11.   

    放了一个textbox控件在窗体上,怎么在执行的时候无法取得textbox.text这个参数,你们说的我都试过了,不行啊,崩溃了!!!
      

  12.   

    1.放一个TextBox控件在窗体上,把TextBox的ID修改为 txtStationName
    2.放一个Button控件在窗体上,双击这个Button,在后台的Click事件中写如下代码string text = txtStationName.Text;
    string strsql = "select station_name from station where station_name='" + text + "'";
    经过以上步骤后,当你在文本框中输入后,点击按钮就可以在后台代码中取得这个文本框的信息了。
      

  13.   

    谢谢你了,问题解决了!!!可是为什么以前用textbox1这个ID就不行?
      

  14.   

    "select station_name from station where station_name='" + text; 
      

  15.   


    string strsql="select station_name from station where station_name='"+text+"'"