我查询数据库时,为什么出现错误如下:信息错误无法创建 stutable 的子列表
主要代码如下:
    //如果没有WHERE查询子句形成的话,则形成,则形成WHERE
    //查询子句,并保存一份副本在变量temp_string中
    temp_string = this.textBoxoption.Text + this.comboBoxlogic1.Text + temp_text;
    sql_string = this.comboBoxkey.Text + this.comboBoxlogic1.Text + temp_text; 
       m_nSqlstring = "SELECT * FROM stutable WHERE '" + sql_string +"'";
       if(search1.m_nSqlstring != "")
       {
SqlConnection yzCon = new SqlConnection(yzconn);
SqlDataAdapter yzcomm = new SqlDataAdapter(search1.m_nSqlstring ,yzCon); DataSet ds = new DataSet();
yzcomm.Fill(ds);
DataView source = new DataView(ds.Tables[0]);
dataGrid1.DataSource = source;
dataGrid1.SetDataBinding(m_dataset,"stutable");
        }

解决方案 »

  1.   

    m_nSqlstring = "SELECT * FROM stutable WHERE '" + sql_string +"'";不能这么写 单引号的位置不对
      

  2.   

    SQL语句有问题,怎么WHERE之后直接开始字符串了?
      

  3.   

    你可以设定
    string sql="select * from tb where 1=1"
    条件1
    if(textbox1.Text!=null)sql+=" and "+textbox1.Text
    条件2
    if(textbox2.Text!=null)sql+=" and "+textbox2.Text
      

  4.   

    单引号没问题,但是SQL语句写错了吧?Where后面的变量你要和数据库表中的那个项的值进行比较啊?光写个          WHERE '" + sql_string +"'          算什么意思啊?人不懂,机器更不懂了。
      

  5.   

    语法错误.
     "... where a='"+a+"'";
      

  6.   

    给你个样品吧:string strSQL1 = "SELECT * FROM login where username='" + Originame.Text + "'";
    ^-^
      

  7.   

    谢谢大家的指点!!!
    我本来的意思是sql_string字符串还有象“ 学号 = 23 ”的条件一样的。
    如果是那样的话,又该如何修改??
    由于刚开始做学C#,有很多地方不懂,希望大家多多指教!万分感激
      

  8.   

    我觉得楼主的方法可行,你注意一下string strSQL1 的空格 和sql_string 输入的text的空格试一下。因为不在自己机器上 没法测试
      

  9.   

    对了 你把where也包含到sql_string中;