我查询数据库时,为什么出现错误如下:信息错误无法创建 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");
}
主要代码如下:
//如果没有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");
}
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
"... where a='"+a+"'";
^-^
我本来的意思是sql_string字符串还有象“ 学号 = 23 ”的条件一样的。
如果是那样的话,又该如何修改??
由于刚开始做学C#,有很多地方不懂,希望大家多多指教!万分感激