PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft ADO .NET
Re: Comparing two DataTables
Forums
Newsgroups
Microsoft DotNet
Microsoft ADO .NET
Re: Comparing two DataTables
![]() |
Re: Comparing two DataTables |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
I am using the following VB code inside some unit tests...
Private Sub CompareToSQLServer(ByVal table as DataTable,, ByVal dv As DataView) Dim dt As DataTable = dv.ToTable Assert.AreEqual(table.Columns.Count, dt.Columns.Count) For i As Integer = 0 To dt.Columns.Count - 1 Assert.IsTrue(dt.Columns(i).ColumnName.ToUpper.Contains(table.Columns(i).ColumnName.ToUpper), "column " & i) Assert.AreEqual(table.Columns(i).DataType, dt.Columns(i).DataType, "column " & table.Columns(i).ColumnName) Next Assert.AreEqual(table.Rows.Count, dt.Rows.Count) For i As Integer = 0 To dt.Rows.Count - 1 For c As Integer = 0 To dt.Columns.Count - 1 Select Case table.Rows(i)(c).GetType.Name Case "Decimal" Dim expected As Decimal = dt.Rows(i)(c) Dim actual As Decimal = table.Rows(i)(c) Assert.AreEqual(expected, actual, 0.1, "row " & i & ", column " & c & " differ") Case Else Assert.AreEqual(table.Rows(i)(c), dt.Rows(i)(c), "row " & i & ", column " & c & " differ") End Select Next Next End Sub Hope this helps Ad. "vamsi krishna via .NET 247" <anonymous@dotnet247.com> wrote in message news:OJbFSbUWFHA.128@TK2MSFTNGP10.phx.gbl... > hi, > I am creating two datatabls at run time and adding rows. > at some point i want to compare those two tables. > one way i know is compare row by row . but i want any metohd for this..... > > -------------------------------- > From: vamsi krishna > > ----------------------- > Posted by a user from .NET 247 (http://www.dotnet247.com/) > > <Id>yNXuxpjL5kGQWUvMM13ysw==</Id> |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

