| 
 | 
 
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册  
 
x
 
 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 [dbo].[航班表]"; 
                    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(); 
                } 
可是输入条件查询之后不显示结果如图[img]C:\Users\lx\Desktop\QQ截图20150117104614.jpgC:\Users\lx\Desktop\QQ截图20150117104604.jpg[/img] |   
 
 
 
 |