K
kvg sasi
Guest
Good Day! I trying to do show the Remote Database values in grid View Control. In Grid view Control i showed Field Names but i could not show the values of the table. How to Show the values of the remote database in Grid View control.
And Below is My code :
SqlConnection cn = null;
string connectString = "";
SqlCommand cmd = null;
SqlDataReader rdr = default(SqlDataReader);
SqlDataAdapter sdr = default(SqlDataAdapter);
connectString = string.Format("Data Source = 192.168.1.105,1433;Initial Catalog=idb;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 tAerator", cn);
cmd.CommandType = CommandType.Text;
rdr = cmd.ExecuteReader();
while (rdr.Read())
{
//using (DataTable dt = new DataTable())
//{
//sdr.Fill(dt);
dataGridView1.AutoGenerateColumns = false;
dataGridView1.ColumnCount = 21;
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[2].Name = "fldAEfdaa";
dataGridView1.Columns[2].HeaderText = "fldAEfdaa";
dataGridView1.Columns[3].Name = "fldAEftaa";
dataGridView1.Columns[3].HeaderText = "fldAEftaa";
dataGridView1.Columns[4].Name = "fldAEahrpm";
dataGridView1.Columns[4].HeaderText = "fldAEahrpm";
dataGridView1.Columns[5].Name = "fldAEspckt1";
dataGridView1.Columns[5].HeaderText = "fldAEspckt1";
dataGridView1.Columns[6].Name = "fldAEapr";
dataGridView1.Columns[6].HeaderText = "fldAEapr";
dataGridView1.Columns[7].Name = "fldAEihpr";
dataGridView1.Columns[7].HeaderText = "fldAEihpr";
dataGridView1.Columns[8].Name = "fldAEdout";
dataGridView1.Columns[8].HeaderText = "fldAEdout";
dataGridView1.Columns[9].Name = "fldAEgfr";
dataGridView1.Columns[9].HeaderText = "fldAEgfr";
dataGridView1.Columns[10].Name = "fldAEtmpdel";
dataGridView1.Columns[10].HeaderText = "fldAEtmpdel";
dataGridView1.Columns[11].Name = "fldAEremrk";
dataGridView1.Columns[11].HeaderText = "fldAEremrk";
dataGridView1.Columns[12].Name = "fldAEp1spd";
dataGridView1.Columns[12].HeaderText = "fldAEp1spd";
dataGridView1.Columns[13].Name = "fldAEmhspd";
dataGridView1.Columns[13].HeaderText = "fldAEmhspd";
dataGridView1.Columns[14].Name = "fldAEtbr";
dataGridView1.Columns[14].HeaderText = "fldAEtbr";
dataGridView1.Columns[15].Name = "fldAEdnt";
dataGridView1.Columns[15].HeaderText = "fldAEdnt";
dataGridView1.Columns[16].Name = "fldAEvar";
dataGridView1.Columns[16].HeaderText = "fldAEvar";
dataGridView1.Columns[17].Name = "fldAEshift";
dataGridView1.Columns[17].HeaderText = "fldAEshift";
dataGridView1.Columns[18].Name = "fldAEoprt_nm";
dataGridView1.Columns[18].HeaderText = "fldAEoprt_nm";
dataGridView1.Columns[19].Name = "fldAEinc_nm";
dataGridView1.Columns[19].HeaderText = "fldAEinc_nm";
dataGridView1.Columns[20].Name = "fldAEdtime";
dataGridView1.Columns[20].HeaderText = "fldAEdtime";
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
cn.Close();
}
Thanks & Regards Sasi ................. Go Green
Continue reading...
And Below is My code :
SqlConnection cn = null;
string connectString = "";
SqlCommand cmd = null;
SqlDataReader rdr = default(SqlDataReader);
SqlDataAdapter sdr = default(SqlDataAdapter);
connectString = string.Format("Data Source = 192.168.1.105,1433;Initial Catalog=idb;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 tAerator", cn);
cmd.CommandType = CommandType.Text;
rdr = cmd.ExecuteReader();
while (rdr.Read())
{
//using (DataTable dt = new DataTable())
//{
//sdr.Fill(dt);
dataGridView1.AutoGenerateColumns = false;
dataGridView1.ColumnCount = 21;
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[2].Name = "fldAEfdaa";
dataGridView1.Columns[2].HeaderText = "fldAEfdaa";
dataGridView1.Columns[3].Name = "fldAEftaa";
dataGridView1.Columns[3].HeaderText = "fldAEftaa";
dataGridView1.Columns[4].Name = "fldAEahrpm";
dataGridView1.Columns[4].HeaderText = "fldAEahrpm";
dataGridView1.Columns[5].Name = "fldAEspckt1";
dataGridView1.Columns[5].HeaderText = "fldAEspckt1";
dataGridView1.Columns[6].Name = "fldAEapr";
dataGridView1.Columns[6].HeaderText = "fldAEapr";
dataGridView1.Columns[7].Name = "fldAEihpr";
dataGridView1.Columns[7].HeaderText = "fldAEihpr";
dataGridView1.Columns[8].Name = "fldAEdout";
dataGridView1.Columns[8].HeaderText = "fldAEdout";
dataGridView1.Columns[9].Name = "fldAEgfr";
dataGridView1.Columns[9].HeaderText = "fldAEgfr";
dataGridView1.Columns[10].Name = "fldAEtmpdel";
dataGridView1.Columns[10].HeaderText = "fldAEtmpdel";
dataGridView1.Columns[11].Name = "fldAEremrk";
dataGridView1.Columns[11].HeaderText = "fldAEremrk";
dataGridView1.Columns[12].Name = "fldAEp1spd";
dataGridView1.Columns[12].HeaderText = "fldAEp1spd";
dataGridView1.Columns[13].Name = "fldAEmhspd";
dataGridView1.Columns[13].HeaderText = "fldAEmhspd";
dataGridView1.Columns[14].Name = "fldAEtbr";
dataGridView1.Columns[14].HeaderText = "fldAEtbr";
dataGridView1.Columns[15].Name = "fldAEdnt";
dataGridView1.Columns[15].HeaderText = "fldAEdnt";
dataGridView1.Columns[16].Name = "fldAEvar";
dataGridView1.Columns[16].HeaderText = "fldAEvar";
dataGridView1.Columns[17].Name = "fldAEshift";
dataGridView1.Columns[17].HeaderText = "fldAEshift";
dataGridView1.Columns[18].Name = "fldAEoprt_nm";
dataGridView1.Columns[18].HeaderText = "fldAEoprt_nm";
dataGridView1.Columns[19].Name = "fldAEinc_nm";
dataGridView1.Columns[19].HeaderText = "fldAEinc_nm";
dataGridView1.Columns[20].Name = "fldAEdtime";
dataGridView1.Columns[20].HeaderText = "fldAEdtime";
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
cn.Close();
}
Thanks & Regards Sasi ................. Go Green
Continue reading...