Demir Acar

Demir Acar

  • NA
  • 98
  • 25.3k

Compare value of datagrid with value selected from database

May 24 2014 8:04 AM
Hi ;

I fill to grid with excel data and want to compare if value exists on database or not ?

 for (int i = 0; i < dataGridView1.RowCount; i++)
                if (radioButton1.Checked==true)
            {
                string strConn = @"Data Source='" + dbconfig.tb1 + "';Initial Catalog='" + dbconfig.tb2 + "';user='" + dbconfig.tb3 + "';pwd='" + dbconfig.tb4 + "'";
                SqlConnection conn = new SqlConnection(strConn);
                conn.Open();
                SqlCommand cmd = new SqlCommand("SELECT CODE  FROM LG_" + dbconfig.tb5 + "_TABLE WHERE CODE NOT LIKE '" + dataGridView1.Rows[i].Cells[0].Value + "'", conn);
                cmd.ExecuteNonQuery();
                SqlDataReader reader = cmd.ExecuteReader();
                if(reader.Read())
                {
                    MessageBox.Show("Check ITEMS" + reader[i].ToString());
                }
                conn.Close();
            }

Answers (2)