小弟最近在做老师布置的作业,要求开发一个学生成绩管理系统,由于比较菜,有些功能无法实现,望高手指教下,呵呵!
  例如,我在做一个成绩查询的窗体,有几个textbox和combobox,和一个datagidview,一个查询button,请问如何实现跟距combobox选到的值,和textbox输入的值
 来确定查询的条件,一点查询button,就在datagidvie中输出符合条件的记录!数据库用的sql2000,希望达人指教下!

解决方案 »

  1.   

    Sql="select * from tablename where fieldname1='"+textbox.text+"'  and fieldname2='"+combbox.text+"'  ";
      
    *****************************************************************************
    欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) http://feiyun0112.cnblogs.com/
      

  2.   

    tableName
    =========================
    id    name     type
    1      aa       1
    2      bb       1
    3      cc       2
    string strSql = "select * from tableName where 1=1 ";
    if(textbox.Text.Trim().Length> 0)
    {
      strSql +=" and name = '"+textbox.Text.Trim()+"'";
    }
    if(combobox.SelectedIndex != -1)
    {
      strSql +=" and type = '"+combobox.SelectedValue +"'";
    }
     
      

  3.   

    string value = textbox.Text;
    string sql = "";
    if(combobox.Checked)
    {
         sql= "````````````````````````````````````````";
    else if(combobox1.Checked)
    {
         sql= "````````````````````````````````````````";
    }
    else if(combobox2.Checked)
    {
         sql= "````````````````````````````````````````";
    }
    dataGridView.DataSource = ``````````
    `````````````````````````````
      

  4.   

        你要的功能可以通过动态绑定来实现。我假定的你的数据库表名为DB,页面上有一个TEXTBOX控件textbox1和一个COMBOBOX控件combobox1吧。下面是示例代码:
    public void button1_click()
    {
     sqlconnection conn = new sqlconnection(connetionstring);//connectionstring是你的连接字符串
     conn.open();
     string str = "select * from DB where  ='"+textbox1.text.trim()+"' and sex = '"+combobox1.text.trim()+"';
     sqldataadapter da = new sqldataadapter(select_stu,conn);
     dataset ds = new dataset();
     da.Fill(ds);
     datagridview1.datasource = ds.tables[0].defaultview;
      }   需要引用命名空间----using System.Data.Sqlclient;