DataView not writing changes to DataSet????

T

twsmith

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?
 
T

twsmith

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();
}
 
M

Marina

Have you tried looking directly through the dataset, not the dataview?

twsmith said:
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?




.
 
T

twsmith

Ok, I see your point - isolate the problem to the dataset-
dataadapter step. I will inspect that tonight.

I can tell you this however if I add

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.



-----Original Message-----
Have you tried looking directly through the dataset, not the dataview?

twsmith said:
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?

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?




.


.
 
P

Puspak Barua

I must admit that I didn't look into it very deeply, but
I had a similar problem, in my case, the control on the
form was bound to a column of a datatable. I had to call
the relevant currency manager's EndCurrentEdit method
before it could see the row as being modified. After that
when I called the data adapter's 'update' method, it
worked.
Let me know if it helped you.
 
T

twsmith

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 said:
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?

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?




.


.
 
T

twsmith

Puspak, thanks for you interest. I will try that and
report back.

I doubt this is it though. I have another textbox control
on the same form bound to a different table and it updates
fine - none of the code is different. So I think there
must be a problem with the update logic.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top