Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Apr 09, 2012 07:01 PM by customer22
Member
67 Points
164 Posts
Apr 06, 2012 04:25 PM|LINK
Hello:
I need to compare the third column: Month each row. For example: the second row of Month at original table is 2,
The comparable table is 3. The twelfth column of Month at original table is 12. The comparable table is 13.
If there is the difference, give the message: it is different.
Is any idea how to accomplish this?
Thank you very much
Original Table
Name NameID Month Base Factor JJ 22 1 1 0 JJ 22 2 2 0 JJ 22 3 3 0 JJ 22 4 4 0 JJ 22 5 5 0 JJ 22 6 6 0 JJ 22 7 7 0 JJ 22 8 8 0 JJ 22 9 9 0 JJ 22 10 10 0 JJ 22 11 11 0 JJ 22 12 12 0 Comparable table Name NameID Month Base Factor JJ 22 1 1 0 JJ 22 3 3 0 JJ 22 4 4 0 JJ 22 5 5 0 JJ 22 6 6 0 JJ 22 7 7 0 JJ 22 8 8 0 JJ 22 9 9 0 JJ 22 10 10 0 JJ 22 11 11 0 JJ 22 12 12 0 JJ 22 13 12 0
All-Star
16310 Points
2773 Posts
Apr 06, 2012 05:25 PM|LINK
Hi,
http://stackoverflow.com/questions/9217134/compare-each-rows-column-to-a-particular-rows-column
http://stackoverflow.com/questions/8156014/comparing-two-tables-for-each-column-of-each-row-and-result-as-log-variable
Thanks...
Star
10672 Points
2426 Posts
Apr 06, 2012 05:36 PM|LINK
Do you mean that you want to check whether the values in corresponding rows of column 3 in both the tables are identical or not?
Are they Database tables? Please make it clear.
B
Apr 06, 2012 08:14 PM|LINK
Thanks for all responses. Yes, I would like to check the values in corresponding each row of column 3 in both the tables are identical. They are database tables.
Apr 07, 2012 07:15 PM|LINK
Try something like this...
private void matchColumns() { string constr = ConfigurationManager.ConnectionStrings["YourString"].ConnectionString; SqlConnection con = new SqlConnection(constr); con.Open(); string qry1 = "SELECT * FROM tbloriginal"; SqlCommand cmd1 = new SqlCommand (qry1,con); SqlDataAdapter da1 = new SqlDataAdapter(cmd1); DataTable dt1 = new DataTable(); da1.Fill(dt1); string qry2 = "SELECT * FROM tblcompare"; SqlCommand cmd2 = new SqlCommand(qry2, con); SqlDataAdapter da2 = new SqlDataAdapter(cmd2); DataTable dt2 = new DataTable(); da2.Fill(dt2); for (int I = 0; I <= dt1.Rows.Count - 1; I++) { string value1 = dt1.Rows[I][2].ToString(); string value2 = dt2.Rows[I][2].ToString(); string rowId = dt1.Rows[I][1].ToString(); if(value1 != value2) { Response.Write ("For NameId " + rowId + ": Column 2 mismatch <br>"); } }
con.Close(); }
Apr 09, 2012 07:01 PM|LINK
Thank you very much!
Do you know any way to wrote sql query script to complish it? I am using sql server.
customer22
Member
67 Points
164 Posts
How to compare each row of the column
Apr 06, 2012 04:25 PM|LINK
Hello:
I need to compare the third column: Month each row. For example: the second row of Month at original table is 2,
The comparable table is 3. The twelfth column of Month at original table is 12. The comparable table is 13.
If there is the difference, give the message: it is different.
Is any idea how to accomplish this?
Thank you very much
Original Table
abiruban
All-Star
16310 Points
2773 Posts
Re: How to compare each row of the column
Apr 06, 2012 05:25 PM|LINK
Hi,
http://stackoverflow.com/questions/9217134/compare-each-rows-column-to-a-particular-rows-column
http://stackoverflow.com/questions/8156014/comparing-two-tables-for-each-column-of-each-row-and-result-as-log-variable
Thanks...
***DON'T FORGET TO CLICK “MARK AS ANSWER” ON THE POST IF HELPED YOU.
basheerkal
Star
10672 Points
2426 Posts
Re: How to compare each row of the column
Apr 06, 2012 05:36 PM|LINK
Do you mean that you want to check whether the values in corresponding rows of column 3 in both the tables are identical or not?
Are they Database tables? Please make it clear.
B
(Talk less..Work more)
customer22
Member
67 Points
164 Posts
Re: How to compare each row of the column
Apr 06, 2012 08:14 PM|LINK
Thanks for all responses. Yes, I would like to check the values in corresponding each row of column 3 in both the tables are identical. They are database tables.
basheerkal
Star
10672 Points
2426 Posts
Re: How to compare each row of the column
Apr 07, 2012 07:15 PM|LINK
Try something like this...
private void matchColumns() { string constr = ConfigurationManager.ConnectionStrings["YourString"].ConnectionString; SqlConnection con = new SqlConnection(constr); con.Open(); string qry1 = "SELECT * FROM tbloriginal"; SqlCommand cmd1 = new SqlCommand (qry1,con); SqlDataAdapter da1 = new SqlDataAdapter(cmd1); DataTable dt1 = new DataTable(); da1.Fill(dt1); string qry2 = "SELECT * FROM tblcompare"; SqlCommand cmd2 = new SqlCommand(qry2, con); SqlDataAdapter da2 = new SqlDataAdapter(cmd2); DataTable dt2 = new DataTable(); da2.Fill(dt2); for (int I = 0; I <= dt1.Rows.Count - 1; I++) { string value1 = dt1.Rows[I][2].ToString(); string value2 = dt2.Rows[I][2].ToString(); string rowId = dt1.Rows[I][1].ToString(); if(value1 != value2) { Response.Write ("For NameId " + rowId + ": Column 2 mismatch <br>"); } }con.Close(); }(Talk less..Work more)
customer22
Member
67 Points
164 Posts
Re: How to compare each row of the column
Apr 09, 2012 07:01 PM|LINK
Thank you very much!
Do you know any way to wrote sql query script to complish it? I am using sql server.