COMPARE VALUE OF DATAGRID WITH VALUE OF SELECTED FROM DATABASE

Demir ACAR

Total Post:11

Points:77
Posted by  Demir ACAR
C# 
C#
 1385  View(s)
Ratings:
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();

            }

        }

  1. Manmohan Jha

    Post:35

    Points:245
    Re: Compare value of datagrid with value of selected from database

    Mr. Birol

    Please elaborate your question...

  1. Demir ACAR

    Post:11

    Points:77
    Re: Compare value of datagrid with value of selected from database

    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.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!