编一个访客登记程序,要实现根据指定条件查询记录功能;又两个TextBox控件,一个指定列名,一个指定值,用这两个条件查询数据库,并将符合条件的行显示在DataGridView控件中,如何实现,谢谢!

解决方案 »

  1.   

    有什么不会的
    "select * from xxxx where name ='"+ textbox1.text+"'"
      

  2.   

    你还没指定列名了,列名也是在TextBox中输入的
      

  3.   

    "select "+textbox1.text+"from xxxx where name ='"+ textbox2.text+"'"
      

  4.   

    你这个我也知道啊,就是列名和值都在textBox中指定,然后返回符合条件的整行,并添加进DataGridView控件中
      

  5.   

    sql="select"+textbox1.text+" from table where name ='"+textbox2.text;
      

  6.   

    string str="select "+textbox1.text+"from xxxx where name ='"+ textbox2.text+"' and 指定值='"+textbox1.text+"'";oledbcommand command=new olendcommand ();
    command.commandtype=command.text;
    command.text=str;
    oledbreader re=command.excuterreader();
    re.read();
      

  7.   


    我用得时SQL Sever 2008的数据库,而且我要返回整行,并添加进DataGridView控件中显示,谢谢!
      

  8.   

    DataTbale myDT =new DataTable();
    string sqlQuery="select * from XXX where 行='"+tb1.text+"' and 列='"+tb2.text"'"
    DataBase myDB=new DataBase();
    myDt=myDataBase.GetlistReDataTable(sqlQuery);
    this.DataGridView.DataSource=myDt;
      

  9.   

    http://blog.sina.com.cn/s/blog_43eb83b90100perh.html
      

  10.   

    //textBox1.Text 取得列名  textBox2.Text 取得该列的值 
    //查询 如下
    string sqlStr = "select * from tableName where " + textBox1.Text + " = '" + textBox2.Text + "'";DataTable _dt = GetTable(sqlStr);//这是我写的方法 GetTable 返回实行sql的结果集datagridview1.DataSource = _dt;