对一个表示这样的 String path1 = @"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\breeze\Documents\master.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
SqlConnection con1 = new SqlConnection(path1);
con1.Open();
String commandtext= "select * from order_b where room_id=";
commandtext = commandtext + textBox1.Text;
SqlDataAdapter sda = new SqlDataAdapter(commandtext, con1);
masterDataSet ds1= new masterDataSet();
sda.Fill(ds1,"order_b");
this.main.Show();
this.main.dataGridView2.Visible = true;
this.main.dataGridView1.Visible = false;
this.main.dataGridView2.DataSource = ds1.Tables["order_b"] .DefaultView;
con1.Close();
ds1.Dispose();
this.Close(); (这个表即使输入对的条件也没有返回值,二在开始显示主窗口的时候可以显示数据库中的数据而一旦进行之后查询就不行了)
对于第二个表的查询是对的
如下: String path = @"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\breeze\Documents\master.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
SqlConnection con = new SqlConnection(path);
con.Open();
String commandtext1 = "select * from floor where room_id=";
commandtext1=commandtext1 +textBox1 .Text;
SqlDataAdapter sda = new SqlDataAdapter(commandtext1 , con);
masterDataSet ds = new masterDataSet();
sda.Fill(ds, "FLOOR");
this.main .Show();
this.main.dataGridView1.Visible = true;
this.main .dataGridView2.Visible = false;
this.main.dataGridView1 .DataSource = ds.Tables["floor"].DefaultView;
con.Close();
this.Close();
完全可以得到想要的结果,求助!
SqlConnection con1 = new SqlConnection(path1);
con1.Open();
String commandtext= "select * from order_b where room_id=";
commandtext = commandtext + textBox1.Text;
SqlDataAdapter sda = new SqlDataAdapter(commandtext, con1);
masterDataSet ds1= new masterDataSet();
sda.Fill(ds1,"order_b");
this.main.Show();
this.main.dataGridView2.Visible = true;
this.main.dataGridView1.Visible = false;
this.main.dataGridView2.DataSource = ds1.Tables["order_b"] .DefaultView;
con1.Close();
ds1.Dispose();
this.Close(); (这个表即使输入对的条件也没有返回值,二在开始显示主窗口的时候可以显示数据库中的数据而一旦进行之后查询就不行了)
对于第二个表的查询是对的
如下: String path = @"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\breeze\Documents\master.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
SqlConnection con = new SqlConnection(path);
con.Open();
String commandtext1 = "select * from floor where room_id=";
commandtext1=commandtext1 +textBox1 .Text;
SqlDataAdapter sda = new SqlDataAdapter(commandtext1 , con);
masterDataSet ds = new masterDataSet();
sda.Fill(ds, "FLOOR");
this.main .Show();
this.main.dataGridView1.Visible = true;
this.main .dataGridView2.Visible = false;
this.main.dataGridView1 .DataSource = ds.Tables["floor"].DefaultView;
con.Close();
this.Close();
完全可以得到想要的结果,求助!
这里有没有跟踪呢 看看ds1.Tables["order_b"]有没有数据啊
commandtext1=commandtext1 +textBox1 .Text;
改成:
String commandtext1 = "select * from floor where room_id='";
commandtext1=commandtext1 +textBox1 .Text+"'";
试一下
我没测试,只是看到这儿貌似可以改改
进行查询时跟踪一下语句 看看是不是语句错误 或者就是查询时ds1.Tables["order_b"]没有重新取数据
String commandtext= "select * from order_b";作测试.