Compare value of datagrid with value of selected from database

Total Post:11

Points:77
C# 
C#
 1620  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. Post:33

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

    Mr. Birol

    Please elaborate your question...

  1. 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.

      Modified On Apr-04-2018 05:21:09 AM

Answer

NEWSLETTER

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