How to show more than one table in single Data Grid Control

  • Thread starter Thread starter kvg sasi
  • Start date Start date
K

kvg sasi

Guest
Good Day! I showed single remote database table in Data Grid View Control. But i dont know how to show more than one table in single Data grid view control. I am using more than one tab page. every tab pages are contains different field names. I want to show different tab page remote database table into a single data grid view control.

code is:


dataGridView1.AutoGenerateColumns = false;
dataGridView1.ColumnCount = 20;

SqlConnection cn = null;
string connectString = "";
SqlCommand cmd = null;
SqlDataReader rdr = default(SqlDataReader);

connectString = string.Format("Data Source = 192.168.1.105,1433;Initial Catalog=itcdb;Persist Security Info=True;User ID=wince;Password=wince1;");
cn = new SqlConnection(connectString);

try
{
if (cn.State == ConnectionState.Closed)
{
cn.Open();
}
}
catch (Exception ex)
{
MessageBox.Show("Open Error");
MessageBox.Show(ex.Message);
}



try
{

cmd = new SqlCommand("select * from tAerator1", cn);
cmd.CommandType = CommandType.Text;
SqlDataAdapter sdr = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sdr.Fill(dt);
rdr = cmd.ExecuteReader();

while (rdr.Read())
{
dataGridView1.Columns[0].Name = "fldAEftba";
dataGridView1.Columns[0].HeaderText = "fldAEftba";
dataGridView1.Columns[0].DataPropertyName = "fldAEftba";

dataGridView1.Columns[1].Name = "fldAEfdba";
dataGridView1.Columns[1].HeaderText = "fldAEfdba";
dataGridView1.Columns[1].DataPropertyName = "fldAEfdba";


dataGridView1.Columns[2].Name = "fldAEfdaa";
dataGridView1.Columns[2].HeaderText = "fldAEfdaa";
dataGridView1.Columns[2].DataPropertyName = "fldAEfdaa";


dataGridView1.Columns[3].Name = "fldAEftaa";
dataGridView1.Columns[3].HeaderText = "fldAEftaa";
dataGridView1.Columns[3].DataPropertyName = "fldAEftaa";


dataGridView1.Columns[4].Name = "fldAEahrpm";
dataGridView1.Columns[4].HeaderText = "fldAEahrpm";
dataGridView1.Columns[4].DataPropertyName = "fldAEahrpm";


dataGridView1.Columns[5].Name = "fldAEspckt1";
dataGridView1.Columns[5].HeaderText = "fldAEspckt1";
dataGridView1.Columns[5].DataPropertyName = "fldAEspckt1";


dataGridView1.Columns[6].Name = "fldAEapr";
dataGridView1.Columns[6].HeaderText = "fldAEapr";
dataGridView1.Columns[6].DataPropertyName = "fldAEapr";



dataGridView1.Columns[7].Name = "fldAEihpr";
dataGridView1.Columns[7].HeaderText = "fldAEihpr";
dataGridView1.Columns[7].DataPropertyName = "fldAEihpr";


dataGridView1.Columns[8].Name = "fldAEdout";
dataGridView1.Columns[8].HeaderText = "fldAEdout";
dataGridView1.Columns[8].DataPropertyName = "fldAEdout";


dataGridView1.Columns[9].Name = "fldAEgfr";
dataGridView1.Columns[9].HeaderText = "fldAEgfr";
dataGridView1.Columns[9].DataPropertyName = "fldAEgfr";


dataGridView1.Columns[10].Name = "fldAEtmpdel";
dataGridView1.Columns[10].HeaderText = "fldAEtmpdel";
dataGridView1.Columns[10].DataPropertyName = "fldAEtmpdel";


dataGridView1.Columns[11].Name = "fldAEremrk";
dataGridView1.Columns[11].HeaderText = "fldAEremrk";
dataGridView1.Columns[11].DataPropertyName = "fldAEremrk";


dataGridView1.Columns[12].Name = "fldAEp1spd";
dataGridView1.Columns[12].HeaderText = "fldAEp1spd";
dataGridView1.Columns[12].DataPropertyName = "fldAEp1spd";


dataGridView1.Columns[13].Name = "fldAEmhspd";
dataGridView1.Columns[13].HeaderText = "fldAEmhspd";
dataGridView1.Columns[13].DataPropertyName = "fldAEmhspd";


dataGridView1.Columns[14].Name = "fldAEtbr";
dataGridView1.Columns[14].HeaderText = "fldAEtbr";
dataGridView1.Columns[14].DataPropertyName = "fldAEtbr";


dataGridView1.Columns[15].Name = "fldAEdnt";
dataGridView1.Columns[15].HeaderText = "fldAEdnt";
dataGridView1.Columns[15].DataPropertyName = "fldAEdnt";


dataGridView1.Columns[16].Name = "fldAEvar";
dataGridView1.Columns[16].HeaderText = "fldAEvar";
dataGridView1.Columns[16].DataPropertyName = "fldAEvar";


dataGridView1.Columns[17].Name = "fldAEshift";
dataGridView1.Columns[17].HeaderText = "fldAEshift";
dataGridView1.Columns[17].DataPropertyName = "fldAEshift";


dataGridView1.Columns[18].Name = "fldAEoprt_nm";
dataGridView1.Columns[18].HeaderText = "fldAEoprt_nm";
dataGridView1.Columns[18].DataPropertyName = "fldAEoprt_nm";


dataGridView1.Columns[19].Name = "fldAEinc_nm";
dataGridView1.Columns[19].HeaderText = "fldAEinc_nm";
dataGridView1.Columns[19].DataPropertyName = "fldAEinc_nm";
dataGridView1.DataSource = dt;


}


}

catch (Exception ex)
{
MessageBox.Show(ex.Message);
}

cn.Close();





Thanks & Regards Sasi ................. Go Green

Continue reading...
 
Back
Top