-1
我有兩個不同的表,有兩個不同的查詢我想表明一種形式甘願在C#中的形式
string query1 = string.Format("select * from Flat where [Flat_No.]='{0}'",flat.Text);
string query2 = string.Format("select * from 1");
SqlCommand cmd = new SqlCommand(query1, con);
SqlCommand cmd1 = new SqlCommand(query2, con1);
dataview frm1 = new dataview(query1,query2); //the form where data is to be displayed
// on form dataview I have two DataGridViews
public dataview(string a,string b)
{
InitializeComponent();
SqlConnection con = new SqlConnection(Class1.getConnectionString);
//connection name
con.Open();
SqlCommand cmd = new SqlCommand(a , con);
cmd.CommandType = CommandType.Text;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "ss");
dataGridView1.DataSource = ds.Tables["ss"];
con.Close();
SqlConnection con1 = new SqlConnection(Class1.getConnectionString);
//connection name for query1
con1.Open();
SqlCommand cmd1 = new SqlCommand(b, con1);
cmd1.CommandType = CommandType.Text;
SqlDataAdapter da1 = new SqlDataAdapter(cmd1);
DataSet ds1 = new DataSet();
da.Fill(ds1, "aa");
dataGridView2.DataSource = ds1.Tables["aa"];
con1.Close();
}
}
但對結果有兩種datagridviews在兩個不同datagridviews兩個不同表中的數據上面的代碼在數據網格視圖中顯示來自查詢1的數據。 plz幫我解決我該如何解決這個問題?如果以另一種方式讓我知道這一點。我也嘗試使用「+」號合併兩個查詢,但它也沒有證明有幫助。
感謝您的糾正 – user2262892