鱼C论坛

 找回密码
 立即注册
查看: 2675|回复: 0

做个查询界面,想通过两个textbox来输入条件点击一个button控件来在dataGridView控...

[复制链接]
发表于 2015-1-17 10:44:56 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

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]
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-18 23:16

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表