Help in datagridview

  • Thread starter Thread starter Meladl
  • Start date Start date
M

Meladl

Guest
I have combobox column inside datagridview called items name and it's read items from db, and I need to show ID of that items into 2nd column in datagridview while items is selected? my code for first items name column is :

com.Connection = con;
con.Open();
com.CommandText = "select * from Goods";
com.ExecuteNonQuery();
DataTable dt7 = new DataTable();
SqlDataAdapter da7 = new SqlDataAdapter(com);
da7.Fill(dt7);
ComboColumn.DataSource = dt7;
ComboColumn.DisplayMember = "Name";
con.Close();


private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{





int i = 0;

com.Connection = con;
com.CommandText = "select ID from Goods where Name = '" + ComboColumn.DisplayMember + "' ";
con.Open();
com.ExecuteNonQuery();
SqlDataReader dr;
dr = com.ExecuteReader();
while (dr.Read())
{



string id = (string)dr["ID"].ToString();

Continue reading...
 
Back
Top