none
comparing tables data using ado.net RRS feed

  • Question

  • I`m using this code to compare two tables of sql database using the ADO.NET:

                        string SurceQuery = @"SELECT BINARY_CHECKSUM(Acc_Discount_ID,Acc_ID,Acc_Discount_Mat_ID,Acc_Discount_PerCent,Acc_Discount_Selling_Price,Created_ID,Updated_ID,Updated_Date)<br/>                                                         FROM [Acc_DB_Mohtaseb_Empty].[dbo].[Account_Discount]";
                        string DistQuery =@"SELECT BINARY_CHECKSUM(Acc_Discount_ID,Acc_ID,Acc_Discount_Mat_ID,Acc_Discount_PerCent,Acc_Discount_Selling_Price,Created_ID,Updated_ID,Updated_Date)<br/>                                                         FROM[Acc_DB_2011_2]. [dbo].[Account_Discount]";
                        MyConn= new SqlConnection(MySqlServer.MasterConnectionString);
                        SqlCommand SourceComm = new SqlCommand(SurceQuery, MyConn);
                        SqlCommand DistComm = new SqlCommand(DistQuery, MyConn);
                        MyConn.Open();
                        int CheckSumOfSourceTB=-1;
                        if(SourceComm.ExecuteScalar()!=DBNull.Value)
                        CheckSumOfSourceTB = (int)SourceComm.ExecuteScalar();
                        int CheckSumOfDistTB=-1;
                        if (DistComm.ExecuteScalar() != DBNull.Value)
                        CheckSumOfDistTB = (int)DistComm.ExecuteScalar();
    

    at this line :

    CheckSumOfSourceTB = (int)SourceComm.ExecuteScalar();<br/>
    
    I got exception : Object reference not set to an instance of an object.

    but that is not happening for all tables !!!

    have you got any explanation??

    thanks.

    • Moved by Leo Liu - MSFT Wednesday, December 21, 2011 7:49 AM Moved for better support. (From:Visual C# Language)
    Tuesday, December 20, 2011 6:17 PM

Answers

All replies