做个查询界面,想通过两个textbox来输入条件点击一个button控件来在dataGridView控...
private void button1_Click(object sender, EventArgs e){
string str1; //保存txtBox1中的a内容
str1 = textBox1.Text.Trim();
string str2; //保存txtBox2中的a内容
str2 = textBox2.Text.Trim();
if (str1 == "")
{
MessageBox.Show("请输入要查询的内容!");
textBox1.Focus();
}
else
{
if (str2 == "")
{
MessageBox.Show("请输入要查询的内容!");
textBox1.Focus();
}
else
{
SqlConnection con = new SqlConnection();
string strConnect = "Data Source=127.0.0.1;Initial Catalog=航空订票系统;Persist Security Info=True;User ID=sa;Password=123456";
con.ConnectionString = strConnect;
con.Open();
SqlCommand com = new SqlCommand();
string sql = "SELECT * FROM .[航班表]";
com.CommandText = string.Format(sql, str1, str2);
SqlDataAdapter da = new SqlDataAdapter(sql, con);
DataSet ds = new DataSet();
da.Fill(ds, "航班表");
DataTable dt = ds.Tables["航班表"];
dataGridView1.DataSource = ds.Tables["航班表"];
con.Close();
}
可是输入条件查询之后不显示结果如图C:\Users\lx\Desktop\QQ截图20150117104614.jpgC:\Users\lx\Desktop\QQ截图20150117104604.jpg
页:
[1]