Re: Problem With DataRow Rowstate by Derek
Derek
Thu Jul 31 11:55:26 CDT 2003
This is a multi-part message in MIME format.
------=_NextPart_000_0041_01C3575A.A1D01E30
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Marco, I'm getting a rowState =3D modified in C#, after the first edit =
update to the row in the DataTable...hmm...:
...
TableOfDeletes =3D dsAuthors.Tables["authors"].Clone();
ry =3D TableOfDeletes.NewRow();
TableOfDeletes.Rows.Add( ry);
ry[0] =3D "111-11-1111";
TableOfDeletes.AcceptChanges(); //ry is now unchanged
ry[0] =3D "333-33-3333"; //ry is now modified
...
I'll try it in VB...
BTW, Did you check this in the debugger?
Derek LaZard
"Marco Gatto" <marcogatto@inwind.it> wrote in message =
news:c7545cd7.0307302247.1847258d@posting.google.com...
> Sorry Derek but I didn't explain very well.... :)
>=20
> Step1 Insert New Row X ----> Detached (OK)
> Step2 Add X ----> Added (OK)
> Step3 AcceptChanges ----> Unchanged(OK)
> Step4 Set New Value (Foo2) ----> Unchanged(NOOO)
> Step5 Set New Value (Foo3) ----> Modified (...)
>=20
> Marco Gatto
>=20
> "Derek LaZard" <derekll@mindspring.com> wrote in message =
news:<ehE97AtVDHA.532@TK2MSFTNGP10.phx.gbl>...
> > Hi Marco.
> >=20
> > >>after an
> > >>Acceptchanges() on DataTable that contains X. After this operation
> > >>DataRow.Rowstate is Unchanged... strange... it must be Modified ..
> >=20
> > After changes are accepted the rowstate is now Unchanged. :)
> > [dataAdapter.Fill() and .Update() resets the rowstates to =
unchanged...
> >=20
> > Derek LaZard
> >=20
> >=20
> > "Marco Gatto" <marcogatto@inwind.it> wrote in message
> > news:c7545cd7.0307290321.1f2b09b1@posting.google.com...
> > > 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 =3D New Data.DataTable()
> > > mConn =3D New SqlClient.SqlConnection("Data
> > > Source=3Dtest-srv;Integrated Security=3DSSPI;Initial =
Catalog=3DTest")
> > > mDataAdapter =3D New SqlClient.SqlDataAdapter("SELECT ID,
> > > Descrizione FROM Table", mConn)
> > >
> > > mDataAdapter.FillSchema(mDataTable, SchemaType.Mapped)
> > > mRow =3D mDataTable.NewRow()
> > > End Sub
> > >
> > >
> > > Public Sub Insert()
> > > If mRow.RowState <> DataRowState.Detached Then Exit Sub
> > > mRow(0) =3D "c51ac21a-05bc-475c-ad75-1affd8f980c3"
> > > mRow(1) =3D "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) =3D "Foo2"
> > > Debug.WriteLine(mRow(1, DataRowVersion.Original) & " " &
> > > mRow(1, DataRowVersion.Current) & " " & mRow.RowState)
> > >
> > > mRow(1) =3D "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=3D
> > > Unchanged) but when I set:
> > > mRow(1) =3D "Foo2"
> > >
> > > mRow.rowstate remains Unchanged....
> > >
> > > Please Help me!!
> > >
> > > Marco Gatto
------=_NextPart_000_0041_01C3575A.A1D01E30
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1106" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT size=3D2>Marco, I'm getting a rowState =3D modified in C#, =
after the=20
first edit update to the row in the DataTable...hmm...:</FONT></DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV><FONT size=3D2>...</FONT></DIV>
<DIV><FONT size=3D2>TableOfDeletes =3D=20
dsAuthors.Tables["authors"].Clone();</FONT></DIV>
<DIV><FONT size=3D2>ry =3D TableOfDeletes.NewRow();</FONT></DIV>
<DIV><FONT size=3D2>TableOfDeletes.Rows.Add( ry);</FONT></DIV>
<DIV><FONT size=3D2>ry[0] =3D "111-11-1111";</FONT></DIV>
<DIV><FONT size=3D2>TableOfDeletes.AcceptChanges(); =
//ry is now=20
unchanged</FONT></DIV>
<DIV><FONT size=3D2>ry[0] =3D "333-33-3333"; =
=20
//ry is now=20
modified</FONT></DIV>
<DIV><FONT size=3D2>...</FONT></DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV><FONT size=3D2>I'll try it in VB...</FONT></DIV>
<DIV><FONT size=3D2>BTW, Did you check this in the =
debugger?</FONT></DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV><FONT size=3D2>Derek LaZard</FONT></DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV><FONT size=3D2>"Marco Gatto" <</FONT><A=20
href=3D"mailto:marcogatto@inwind.it"><FONT=20
size=3D2>marcogatto@inwind.it</FONT></A><FONT size=3D2>> wrote in =
message=20
</FONT><A =
href=3D"news:c7545cd7.0307302247.1847258d@posting.google.com"><FONT=20
size=3D2>news:c7545cd7.0307302247.1847258d@posting.google.com</FONT></A><=
FONT=20
size=3D2>...</FONT></DIV><FONT size=3D2>> Sorry Derek but I didn't =
explain very=20
well.... :)<BR>> <BR>> Step1 Insert New Row =
X =20
----> Detached (OK)<BR>> Step2 Add=20
X =
=20
----> Added (OK)<BR>> Step3=20
AcceptChanges ---->=20
Unchanged(OK)<BR>> Step4 Set New Value (Foo2) ---->=20
Unchanged(NOOO)<BR>> Step5 Set New Value (Foo3) ----> Modified=20
(...)<BR>> <BR>> Marco Gatto<BR>> <BR>> "Derek LaZard" =
<</FONT><A=20
href=3D"mailto:derekll@mindspring.com"><FONT=20
size=3D2>derekll@mindspring.com</FONT></A><FONT size=3D2>> wrote in =
message=20
</FONT><A href=3D"news:<ehE97AtVDHA.532@TK2MSFTNGP10.phx.gbl"><FONT=20
size=3D2>news:<ehE97AtVDHA.532@TK2MSFTNGP10.phx.gbl</FONT></A><FONT=20
size=3D2>>...<BR>> > Hi Marco.<BR>> > <BR>> > =
>>after=20
an<BR>> > >>Acceptchanges() on DataTable that contains X. =
After this=20
operation<BR>> > >>DataRow.Rowstate is Unchanged... =
strange... it=20
must be Modified ..<BR>> > <BR>> > After changes are =
accepted the=20
rowstate is now Unchanged. :)<BR>> > [dataAdapter.Fill() and =
.Update()=20
resets the rowstates to unchanged...<BR>> > <BR>> > Derek=20
LaZard<BR>> > <BR>> > <BR>> > "Marco Gatto" =
<</FONT><A=20
href=3D"mailto:marcogatto@inwind.it"><FONT=20
size=3D2>marcogatto@inwind.it</FONT></A><FONT size=3D2>> wrote in =
message<BR>>=20
> </FONT><A =
href=3D"news:c7545cd7.0307290321.1f2b09b1@posting.google.com"><FONT=20
size=3D2>news:c7545cd7.0307290321.1f2b09b1@posting.google.com</FONT></A><=
FONT=20
size=3D2>...<BR>> > > Hello Everyone<BR>> > > I've got =
a problem=20
when I set a value into a DataRow X after an<BR>> > > =
Acceptchanges()=20
on DataTable that contains X. After this operation<BR>> > >=20
DataRow.Rowstate is Unchanged... strange... it must be Modified =
..<BR>> >=20
> isn't it?<BR>> > ><BR>> > ><BR>> > > I =
you see=20
the following code (just "little boring"...)<BR>> > ><BR>> =
> >=20
Public Class testclass<BR>> > > =
Protected=20
mDataTable As Data.DataTable<BR>> > > =
Protected=20
mRow As Data.DataRow<BR>> > > Protected =
mDataAdapter As SqlClient.SqlDataAdapter<BR>> >=20
> Protected mConn As =
SqlClient.SqlConnection<BR>>=20
> > '----------------------------<BR>> =
>=20
> ' New<BR>> > =
> =20
'----------------------------<BR>> > > =
Public=20
Sub New()<BR>> > =
> =20
mDataTable =3D New Data.DataTable()<BR>> >=20
> mConn =3D New=20
SqlClient.SqlConnection("Data<BR>> > > =
Source=3Dtest-srv;Integrated=20
Security=3DSSPI;Initial Catalog=3DTest")<BR>> >=20
> mDataAdapter =3D =
New=20
SqlClient.SqlDataAdapter("SELECT ID,<BR>> > > Descrizione FROM =
Table",=20
mConn)<BR>> > ><BR>> >=20
> =20
mDataAdapter.FillSchema(mDataTable, SchemaType.Mapped)<BR>> >=20
> mRow =3D=20
mDataTable.NewRow()<BR>> > > End =
Sub<BR>>=20
> ><BR>> > ><BR>> > > =
Public Sub=20
Insert()<BR>> > =
> If=20
mRow.RowState <> DataRowState.Detached Then Exit Sub<BR>> >=20
> mRow(0) =3D=20
"c51ac21a-05bc-475c-ad75-1affd8f980c3"<BR>> >=20
> mRow(1) =3D =
"Hello!!"<BR>>=20
> ><BR>> > =
> =20
'--------------------------------------------<BR>> >=20
> ' Delete evenually =
records=20
from DataTable<BR>> > =
> =20
'--------------------------------------------<BR>> >=20
> =
mDataTable.Clear()<BR>>=20
> > =20
'-----------------------------------------<BR>> >=20
> ' AddRow<BR>> =
>=20
> =20
'-----------------------------------------<BR>> >=20
> =20
mDataTable.Rows.Add(mRow)<BR>> >=20
> =20
Debug.WriteLine(mRow.RowState)<BR>> > ><BR>> >=20
> =20
'---------------------------<BR>> >=20
> 'Accept<BR>> =
>=20
> =20
'----------------------------<BR>> >=20
> =20
mDataTable.AcceptChanges()<BR>> >=20
> =
Debug.WriteLine(mRow(1,=20
DataRowVersion.Original) & " " &<BR>> > > mRow(1,=20
DataRowVersion.Current) & " " & mRow.RowState)<BR>> >=20
> =20
'----------------------------------------<BR>> >=20
> ' Try to change =
value=20
BUT!!!!!<BR>> > =
> =20
'----------------------------------------<BR>> >=20
> mRow(1) =3D =
"Foo2"<BR>>=20
> > =20
Debug.WriteLine(mRow(1, DataRowVersion.Original) & " " &<BR>> =
>=20
> mRow(1, DataRowVersion.Current) & " " & =
mRow.RowState)<BR>> >=20
><BR>> > > =
mRow(1) =3D=20
"Foo3"<BR>> > > =
Debug.WriteLine(mRow(1, DataRowVersion.Original) & " " &<BR>> =
>=20
> mRow(1, DataRowVersion.Current) & " " & =
mRow.RowState)<BR>> >=20
><BR>> > > End Sub<BR>> > =
><BR>>=20
> > AND CLIENT USER...<BR>> > ><BR>> >=20
> Private Sub Button1_Click(ByVal sender As=20
System.Object, ByVal e<BR>> > > As System.EventArgs) Handles=20
Button1.Click<BR>> > =
> =20
Dim trow As New testclass()<BR>> >=20
> =
trow.Insert()<BR>> >=20
><BR>> > > End Sub<BR>> > =
><BR>>=20
> > End Class<BR>> > ><BR>> > ><BR>> > =
> You=20
can see that after AcceptChanges is all ok... (Rowstate=3D<BR>> > =
>=20
Unchanged) but when I set:<BR>> >=20
> mRow(1) =3D =
"Foo2"<BR>>=20
> ><BR>> > > mRow.rowstate remains Unchanged....<BR>> =
>=20
><BR>> > > Please Help me!!<BR>> > ><BR>> > =
>=20
Marco Gatto</FONT> </BODY></HTML>
------=_NextPart_000_0041_01C3575A.A1D01E30--