帮我看看这段代码,在线等
private void button1_Click(object sender, EventArgs e)
{
string ConStr = @ "Integrated Security=SSPI;database=学生管理;data source=(local) ";
SqlConnection SqlCon = new SqlConnection(ConStr);
string SelectCmd = "select * from student where " + comboBox1.Text + "like \ '% " + textBox1.Text + "%\ ' ";
//string SelectCmd = "select * from student ";
SqlCommand SqlCmd = new SqlCommand(SelectCmd,SqlCon);
DataSet DS = new DataSet();
try
{
SqlCon.Open();
SqlDataAdapter DA = new SqlDataAdapter(SqlCmd);
DA.Fill(DS, "T1 ");
dataGridView1.DataSource = DS.Tables[ "T1 "].DefaultView;
}
catch (Exception ex) { }
finally
{
SqlCon.Close();
}
}
string SelectCmd = "select * from student where " + comboBox1.Text + "like \ '% " + textBox1.Text + "%\ ' ";
请问这段代码有什么问题,怎么我显示不出结果呢,?
//string SelectCmd = "select * from student ";
这个就可以执行出结果,
还有返回的结果不是在我原来已经编辑好的列里面显示的,而是重新新建的列,请问一下高手,应该怎么处理,!
------解决方案--------------------string SelectCmd = "select * from student where " + comboBox1.Text + "like \ '% " + textBox1.Text + "%\ ' ";
该为:
string SelectCmd = "select * from student where " + comboBox1.Text + "like '% " + textBox1.Text + "% ' ";