SQL数据库查询

来源:百度知道 编辑:UC知道 时间:2024/09/24 04:13:07
有谁帮看一下这段代码有什么错误,

private void button3_Click(object sender, EventArgs e)
{
cn.Open();
string strcom = comboBox1.Text;
string str = textBox1.Text;
SqlDataAdapter da = new SqlDataAdapter("select * from tb_07 where strcom ='" + str + "'", cn);
DataSet ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0].DefaultView;
cn.Close();

}
我这个没有使用try catch,他就是什么错误都不报,你帮忙看一下,它上面有什么语法错误吗,
如果是我把 string strcom这一行去掉,效果如下:又可以了。那么我觉得问题就应该出在这个字段了。
private void button3_Click(object sender, EventArgs e)
{
cn.Open();

string str = textBox1.Text;
SqlDataAdapter da = new SqlDataAdapter("select * from tb_07 where 学生姓名='" + str + "'", cn);
DataSet ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSourc

comboBox1 的取值方法不能用comboBox1.Text吧,具体是什么不记得了,你可以查下帮助.
值取出来后用:
SqlDataAdapter da = new SqlDataAdapter("select * from tb_07 where " + strcom + "='" + str + "'", cn);

string strcom = comboBox1.Text; 这句话和其他语句都不相干。
你原来的做法是把strcom放在select语句的where语句中,这肯定是错误的。
-------------------------
报什么错误?

没有问题啊

那一定是strcom 没有获的值!你可以
private void button3_Click(object sender, EventArgs e)
{
string strcom = comboBox1.Text;
response.write(“strcom ”);
}
看能不能输出值!或看下输出什么值!再贴出来吧

老大有没有搞清楚什么是字段,什么是变量?