c #datagridview没有同步

时间:2015-10-17 06:59:55

标签: c# datagridview

我在数据网格视图中显示两个表。我的第一个表应该专门显示在第一行,第二个表应该在下一行中显示。但第二个表也是第一行

//from first table   
using (SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;Database=academic;Trusted_Connection=TRUE"))
{
    con.Open();
    SqlCommand cmd = new SqlCommand("select * from lectureOver", con);
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    da.Fill(dt);
    con.Close();
    dataGridView1.AutoGenerateColumns = false;
    dataGridView1.Columns[0].HeaderText = "Total Attendance";
    dataGridView1.Columns[0].DataPropertyName = "attendanceTotal";
    dataGridView1.DataSource = dt;
}

//from second table
dt = new DataTable();
using (SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;Database=academic;Trusted_Connection=TRUE"))
{
    con.Open();
    SqlCommand cmd = new SqlCommand("select * from Lecture", con);
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    da.Fill(dt);
    con.Close();
    dataGridView1.AutoGenerateColumns = false;
    dataGridView1.Columns[1].HeaderText = "Total Attendance Raw Score";
    dataGridView1.Columns[1].DataPropertyName = "attendanceRawScore";
    dataGridView1.DataSource = dt;
}

0 个答案:

没有答案