请大家帮我看看,为什么我这段程序运行总提示:错误信息无法创建字段stutable的子列表。
大家帮我改改看,这段程序到底哪里有问题呀?
try
{m_nSqlstring = "SELECT * FROM stutable WHERE 年龄 < '"+str+"'";
SqlConnection yzCon = new SqlConnection(yzconn);
yzCon.Open();
SqlDataAdapter yzcomm = new SqlDataAdapter(m_nSqlstring ,yzCon);
DataSet ds = new DataSet();
yzcomm.Fill(ds);
DataView source = new DataView(ds.Tables[0]);
dataGrid1.DataSource = source;
dataGrid1.SetDataBinding(ds,"stutable");
yzCon.Close();
}
catch(Exception err)
{
MessageBox.Show("错误信息" + err.Message);
}
大家帮我改改看,这段程序到底哪里有问题呀?
try
{m_nSqlstring = "SELECT * FROM stutable WHERE 年龄 < '"+str+"'";
SqlConnection yzCon = new SqlConnection(yzconn);
yzCon.Open();
SqlDataAdapter yzcomm = new SqlDataAdapter(m_nSqlstring ,yzCon);
DataSet ds = new DataSet();
yzcomm.Fill(ds);
DataView source = new DataView(ds.Tables[0]);
dataGrid1.DataSource = source;
dataGrid1.SetDataBinding(ds,"stutable");
yzCon.Close();
}
catch(Exception err)
{
MessageBox.Show("错误信息" + err.Message);
}
{m_nSqlstring = "SELECT * FROM stutable WHERE 年龄 < '"+str+"'";
SqlConnection yzCon = new SqlConnection(yzconn);
yzCon.Open();
SqlDataAdapter yzcomm = new SqlDataAdapter(m_nSqlstring ,yzCon);
DataSet ds = new DataSet();
yzcomm.Fill(ds);
DataView source = new DataView(ds.Tables[0]);
dataGrid1.DataSource = source;
yzCon.Close();
}
catch(Exception err)
{
MessageBox.Show("错误信息" + err.Message);
}
dataGrid1.SetDataBinding(ds,"stutable");改为
dataGridl. DataBind();
这里可以不用显示:数据库连接和关闭
alexzhang00() :
用你的方法,我能得出正确的结果。但我不是很明白为什么要把这句话dataGrid1. SetDataBinding(ds,"stutable")删除掉,你能详细的说一下吗?谢谢!!!
就是我把m_nSqlstring = "SELECT * FROM stutable WHERE 年龄 < '"+str+"'";句话改为:
m_nSqlstring = "SELECT * FROM stutable WHERE '" + sql_string + "' ";
sql_string = "年龄 <= 18";
为什么改成这样就不行了,总提示:信息错误第1行'年龄 <= 18'附近有语法错误
请问怎么修改呀????/