Re: DataView not writing changes to DataSet???? by twsmith
twsmith
Tue Aug 19 08:11:31 CDT 2003
I did inspect that the table directly in the data set. The
situation is the same - the value is changed in the table,
the Rowstate remains unchanged and the dataadapter
returns '0' indicating that no rows changes were detected.
DataTable tempTbl = new DataTable();
int intCounter;
intCounter=0;
tempTbl = ds.Tables["tblEvent"];
foreach(DataRow tempDR in tempTbl.Rows)
{
intCounter++;
Console.WriteLine("line: {0}",intCounter);
Console.WriteLine(tempDR[2].ToString());
Console.WriteLine(tempDR.RowState.ToString());
}
So, does this mean my problem is with the update logic
(recall that I am using the commands generated by the
adaptor). No error is thrown and everything looks fine to
me.
Any thing else I should check?
in a parallel email I also noted that:
dr.BeginEdit();
dr[2]=1699;
dr.EndEdit();
to my
foreach (DataRowView dr in DVEventInfo)
{
dr.BeginEdit();
dr[2]=1699;
dr.EndEdit();
Console.WriteLine(dr[2].ToString());
Console.WriteLine(dr.RowVersion);
Console.WriteLine(dr.Row.RowState);
}
then the RowState reads as "Modified" and the
dataAdaptor.Update catches it and updates the database
with new value. So it seems to me that somehow the change
in the text box is not triggering a flip of the RowState.
Tim
>-----Original Message-----
>Have you tried looking directly through the dataset, not
the dataview?
>
>"twsmith" <worldviewtws@msn.com> wrote in message
>news:033801c365c2$6e28e320$a401280a@phx.gbl...
>> Maria, thanks for looking, there is not much code - most
>> of the below is testing with comments
>>
>>
>>
>>
>> Declaration Code
>>
>>
>> DataTable dtEvent = ds.Tables["tblEvent"];
>> DVEventInfo = new DataView(dtEvent);
>> DVEventInfo.AllowDelete=true;
>> DVEventInfo.AllowEdit=true;
>> DVEventInfo.AllowNew=true;
>>
>>
>> this.txtFrom.DataBindings.Add
("Text",DVEventInfo,"efrom");
>> __________________________
>>
>> private void cmdSaveAndExit_Click(object sender,
>> System.EventArgs e)
>>
>> try
>> {
>> DVEventInfo.RowFilter="";
>>
>> //test row
>> //note:*** the value is changed
>> //*** but RowState reads "unchanged"
>> //attempt to update returns a '0'
>> // changes not sent to database
>> foreach (DataRowView dr in DVEventInfo)
>> {
>> Console.WriteLine(dr[2].ToString());
>> Console.WriteLine(dr.Row.RowState);
>> }
>>
>> //test update command
>> SqlCommandBuilder sqkCBEvent = new SqlCommandBuilder
>> (daEvent);
>> //test
>> Console.WriteLine(sqkCBEvent.GetUpdateCommand
>> ().CommandText);
>> Console.WriteLine(this.daEvent.Update(ds,"tblEvent"));
>> }
>> catch(Exception ex)
>> {
>> MessageBox.Show(ex.Message);
>> }
>> this.ParentForm.Close();
>> }
>>
>>
>>
>>
>> >-----Original Message-----
>> >You need to show the relevant code...
>> >
>> >You are not calling AcceptChanges are you?
>> >
>> >"twsmith" <worldviewtws@msn.com> wrote in message
>> >news:043d01c365bc$c44f1540$a101280a@phx.gbl...
>> >> Greetings,
>> >>
>> >> I have a textbox control with has a binding to a
>> DataView
>> >> (which always has only one row). Changes to the row
are
>> >> persisted during the lifetime of the
DataSet/DataTable
>> >> which underlies the DataView. However when I use
>> >> MyDataAdaptor.update() the change is ignored. When I
>> >> programmatically inspect data in the row, I see the
new
>> >> value, but when I look ats it rowstate this is set
>> >> to "unchanged".
>> >>
>> >> Further info:
>> >>
>> >> if I use editbegin() and editend() the rowstate is
>> changed
>> >> to modified. Update then catches the change and
updates
>> >> the database.
>> >>
>> >> The DataView is being used to filter to a single
record
>> to
>> >> supply a form (sorting on an index value of another
>> >> control). So the filter is being changed frequently
>> before
>> >> Update is called. However the changes persist when
rows
>> >> are revisited.
>> >>
>> >> I have another textbox control on the same form,
using a
>> >> different dataview - changes to it are caught and
passed
>> >> on to the update. I see no differences in the
properties
>> >> of the controls or the dataveiws.
>> >>
>> >> I don't think this matters but the data type of the
>> column
>> >> in the database is int, while the textbox is string.
>> >>
>> >> Any ideas?
>> >>
>> >>
>> >
>> >
>> >.
>> >
>
>
>.
>