M
Marco Gatto
Hello Everyone
I've got a problem when I set a value into a DataRow X after an
Acceptchanges() on DataTable that contains X. After this operation
DataRow.Rowstate is Unchanged... strange... it must be Modified ..
isn't it?
I you see the following code (just "little boring"...)
Public Class testclass
Protected mDataTable As Data.DataTable
Protected mRow As Data.DataRow
Protected mDataAdapter As SqlClient.SqlDataAdapter
Protected mConn As SqlClient.SqlConnection
'----------------------------
' New
'----------------------------
Public Sub New()
mDataTable = New Data.DataTable()
mConn = New SqlClient.SqlConnection("Data
Source=test-srv;Integrated Security=SSPI;Initial Catalog=Test")
mDataAdapter = New SqlClient.SqlDataAdapter("SELECT ID,
Descrizione FROM Table", mConn)
mDataAdapter.FillSchema(mDataTable, SchemaType.Mapped)
mRow = mDataTable.NewRow()
End Sub
Public Sub Insert()
If mRow.RowState <> DataRowState.Detached Then Exit Sub
mRow(0) = "c51ac21a-05bc-475c-ad75-1affd8f980c3"
mRow(1) = "Hello!!"
'--------------------------------------------
' Delete evenually records from DataTable
'--------------------------------------------
mDataTable.Clear()
'-----------------------------------------
' AddRow
'-----------------------------------------
mDataTable.Rows.Add(mRow)
Debug.WriteLine(mRow.RowState)
'---------------------------
'Accept
'----------------------------
mDataTable.AcceptChanges()
Debug.WriteLine(mRow(1, DataRowVersion.Original) & " " &
mRow(1, DataRowVersion.Current) & " " & mRow.RowState)
'----------------------------------------
' Try to change value BUT!!!!!
'----------------------------------------
mRow(1) = "Foo2"
Debug.WriteLine(mRow(1, DataRowVersion.Original) & " " &
mRow(1, DataRowVersion.Current) & " " & mRow.RowState)
mRow(1) = "Foo3"
Debug.WriteLine(mRow(1, DataRowVersion.Original) & " " &
mRow(1, DataRowVersion.Current) & " " & mRow.RowState)
End Sub
AND CLIENT USER...
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Dim trow As New testclass()
trow.Insert()
End Sub
End Class
You can see that after AcceptChanges is all ok... (Rowstate=
Unchanged) but when I set:
mRow(1) = "Foo2"
mRow.rowstate remains Unchanged....
Please Help me!!
Marco Gatto
I've got a problem when I set a value into a DataRow X after an
Acceptchanges() on DataTable that contains X. After this operation
DataRow.Rowstate is Unchanged... strange... it must be Modified ..
isn't it?
I you see the following code (just "little boring"...)
Public Class testclass
Protected mDataTable As Data.DataTable
Protected mRow As Data.DataRow
Protected mDataAdapter As SqlClient.SqlDataAdapter
Protected mConn As SqlClient.SqlConnection
'----------------------------
' New
'----------------------------
Public Sub New()
mDataTable = New Data.DataTable()
mConn = New SqlClient.SqlConnection("Data
Source=test-srv;Integrated Security=SSPI;Initial Catalog=Test")
mDataAdapter = New SqlClient.SqlDataAdapter("SELECT ID,
Descrizione FROM Table", mConn)
mDataAdapter.FillSchema(mDataTable, SchemaType.Mapped)
mRow = mDataTable.NewRow()
End Sub
Public Sub Insert()
If mRow.RowState <> DataRowState.Detached Then Exit Sub
mRow(0) = "c51ac21a-05bc-475c-ad75-1affd8f980c3"
mRow(1) = "Hello!!"
'--------------------------------------------
' Delete evenually records from DataTable
'--------------------------------------------
mDataTable.Clear()
'-----------------------------------------
' AddRow
'-----------------------------------------
mDataTable.Rows.Add(mRow)
Debug.WriteLine(mRow.RowState)
'---------------------------
'Accept
'----------------------------
mDataTable.AcceptChanges()
Debug.WriteLine(mRow(1, DataRowVersion.Original) & " " &
mRow(1, DataRowVersion.Current) & " " & mRow.RowState)
'----------------------------------------
' Try to change value BUT!!!!!
'----------------------------------------
mRow(1) = "Foo2"
Debug.WriteLine(mRow(1, DataRowVersion.Original) & " " &
mRow(1, DataRowVersion.Current) & " " & mRow.RowState)
mRow(1) = "Foo3"
Debug.WriteLine(mRow(1, DataRowVersion.Original) & " " &
mRow(1, DataRowVersion.Current) & " " & mRow.RowState)
End Sub
AND CLIENT USER...
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Dim trow As New testclass()
trow.Insert()
End Sub
End Class
You can see that after AcceptChanges is all ok... (Rowstate=
Unchanged) but when I set:
mRow(1) = "Foo2"
mRow.rowstate remains Unchanged....
Please Help me!!
Marco Gatto