I got some code which makes an SQL query and pastes the result into a datagridview. This works perfectly. The code be seen below:
private void FillInDataGrid()
{
string cn = ConfigurationManager.ConnectionStrings["Scratchpad"].ConnectionString;
SqlConnection myConnection = new SqlConnection(cn);
string sql =
"SELECT " +
" dbo.new.[column1], dbo.new.[column2], dbo.new.[column3], dbo.new.[column4] from dbo.new" +
"except " +
"select dbo.old.[column1], dbo.old.[column2], dbo.old.[column3], dbo.old.[column4] from dbo.old"
;
SqlDataAdapter dataadapter = new SqlDataAdapter(sql, myConnection);
DataSet ds = new DataSet();
myConnection.Open();
dataadapter.Fill(ds, "Authors_table");
myConnection.Close();
dataGridView1.DataSource = ds;
dataGridView1.DataMember = "Authors_table";
}
This code displays the values of the row from the new table
if it doenst exists in the old table
. Now I want to color the cells where they differ. So for example if you have those two tables:
new table:
--------------------------------------
| column1 | column2| column3| column4|
--------------------------------------
| 1 | 1 | 1 | 2 |
--------------------------------------
| 2 | 2 | 3 | 2 |
--------------------------------------
| 6 | 7 | 9 | 8 |
--------------------------------------
| 7 | 5 | 34 | 22 |
--------------------------------------
| 3 | 4 | 3 | 3 |
--------------------------------------
old table:
--------------------------------------
| column1 | column2| column3| column4|
--------------------------------------
| 6 | 7 | 9 | 8 |
--------------------------------------
| 7 | 5 | 34 | 22 |
--------------------------------------
| 1 | 1 | 1 | 1 |
--------------------------------------
| 2 | 2 | 2 | 2 |
--------------------------------------
| 3 | 3 | 3 | 3 |
--------------------------------------
So this example would show:
--------------------------------------
| column1 | column2| column3| column4|
--------------------------------------
| 1 | 1 | 1 | *2* |
--------------------------------------
| 2 | 2 | *3* | *2* |
--------------------------------------
| 3 | *4* | *3* | *3* |
--------------------------------------
Where the * 2 *, * 3 * and * 4 * would show a color in the datagridview.
Thanks in advance for your help.