S
Smokey Grindel
Try this code, why are the sames that are the same showing up as different?
when I run this it says they are different values!, but do it with strings
and they say they are the same... I am trying to write code to check if a
date changed in a data row and it is getting no where
Module Module1
Sub Main()
CheckVersionBeforeAccept()
Console.Read()
End Sub
Private Sub CheckVersionBeforeAccept()
'Run a function to create a DataTable with one column.
Dim dataTable As DataTable = MakeTable()
Dim dataRow As DataRow = dataTable.NewRow()
dataRow("FirstName") = Now.Date.Date
dataTable.Rows.Add(dataRow)
dataRow.BeginEdit()
' Edit data but keep the same value.
dataRow(0) = Now.Date.Date
' Uncomment the following line to add a new value.
dataRow(0) = Now.Date.Date
' dataRow(0) = Now.Date.Date
Console.WriteLine(String.Format("FirstName {0}", dataRow(0)))
' Compare the proposed version with the current.
If dataRow.HasVersion(DataRowVersion.Proposed) Then
If dataRow(0, DataRowVersion.Current) Is dataRow(0, DataRowVersion.Proposed)
Then
Console.WriteLine("The original and the proposed are the same.")
dataRow.CancelEdit()
Else
dataRow.AcceptChanges()
Console.WriteLine("The original and the proposed are different.")
End If
End If
End Sub
Private Function MakeTable() As DataTable
' Make a simple table with one column.
Dim dt As New DataTable("dataTable")
Dim firstName As New DataColumn("FirstName", _
Type.GetType("System.DateTime"))
dt.Columns.Add(firstName)
Return dt
End Function
End Module
when I run this it says they are different values!, but do it with strings
and they say they are the same... I am trying to write code to check if a
date changed in a data row and it is getting no where
Module Module1
Sub Main()
CheckVersionBeforeAccept()
Console.Read()
End Sub
Private Sub CheckVersionBeforeAccept()
'Run a function to create a DataTable with one column.
Dim dataTable As DataTable = MakeTable()
Dim dataRow As DataRow = dataTable.NewRow()
dataRow("FirstName") = Now.Date.Date
dataTable.Rows.Add(dataRow)
dataRow.BeginEdit()
' Edit data but keep the same value.
dataRow(0) = Now.Date.Date
' Uncomment the following line to add a new value.
dataRow(0) = Now.Date.Date
' dataRow(0) = Now.Date.Date
Console.WriteLine(String.Format("FirstName {0}", dataRow(0)))
' Compare the proposed version with the current.
If dataRow.HasVersion(DataRowVersion.Proposed) Then
If dataRow(0, DataRowVersion.Current) Is dataRow(0, DataRowVersion.Proposed)
Then
Console.WriteLine("The original and the proposed are the same.")
dataRow.CancelEdit()
Else
dataRow.AcceptChanges()
Console.WriteLine("The original and the proposed are different.")
End If
End If
End Sub
Private Function MakeTable() As DataTable
' Make a simple table with one column.
Dim dt As New DataTable("dataTable")
Dim firstName As New DataColumn("FirstName", _
Type.GetType("System.DateTime"))
dt.Columns.Add(firstName)
Return dt
End Function
End Module