Home > DeveloperSection > Forums > Compare value of datagrid with value of selected from database
Demir ACAR
Demir ACAR

Total Post:11

Points:77
Posted on    May-24-2014 7:15 AM

 C# C# 
Ratings:


 2 Reply(s)
 1153  View(s)
Rate this:

  for (int i = 0; i < dataGridView1.RowCount-1; 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", conn);

                    cmd.ExecuteNonQuery();

                    SqlDataReader reader = cmd.ExecuteReader();

                    while (reader.Read())

                    {

                        if (reader["CODE"].ToString() != dataGridView1.Rows[i++].Cells[2].Value.ToString())

                        {

                            MessageBox.Show(dataGridView1.Rows[i].Cells[2].Value.ToString());

                        }

                    

                    }

                    conn.Close();

            }

        }



Manmohan Jha

Total Post:35

Points:245
Posted on    May-27-2014 8:24 AM

Mr. Birol

Please elaborate your question...

Demir ACAR
Demir ACAR

Total Post:11

Points:77
Posted on    May-27-2014 8:55 AM

I fill to datagrid with excel and want to check data in datagrid and sql value,

For example , My Grid Results

GRID_DATA      DB_DATA

ABD                 GERMANY

GERMANY         ABD

ITALY               UKRAINE

So I want to catch ITALY due to does not exists database.

Thanks in advance

if(radioButton1.Checked == true)

            {for(inti = 0; i < dataGridView1.Rows.Count; i++)      

{stringstrConn = @"Data Source='"+ dbconfig.tb1 + "';Initial Catalog='"+ dbconfig.tb2 + "';user='"+ dbconfig.tb3 + "';pwd='"+ dbconfig.tb4 + "'";

SqlConnectionconn = newSqlConnection(strConn);

conn.Open();

SqlCommandcmd = newSqlCommand("SELECT CODE  FROM TABLE where CODE='"+ dataGridView1.Rows[i].Cells[2].Value.ToString() + "'", conn);

SqlDataReaderreader = cmd.ExecuteReader();

while(reader.Read())

{varsonuc = dataGridView1.Rows[i].Cells[2].Value;

MessageBox.Show("Total"+ dataGridView1.RowCount.ToString() + " Unit Records"+ "\n"+ "\n"+ "mismatched"+ sonuc, "Result", MessageBoxButtons.OK, MessageBoxIcon.Information);

   }

                    conn.Close();

                    reader.Close();

                    }                    

                }


Note : I fill to grid with excel , no datatables or others.


Don't want to miss updates? Please click the below button!

Follow MindStick