Detecting Change in DataSet - Not Working |
|
Author |
Message |
M Thomas
|
Posted: .NET Framework Data Access and Storage, Detecting Change in DataSet - Not Working |
Top |
Using ASP.NET 2, I am having a problem detecting changes to a DataSet which is bound to text fields in a form. The DataChange() method below always returns false.
I am populating text fields in the form as follows:
private void dataLoad(string strSQL) {
ds = sqlClass.getDataSet( "Select * from invcusth where invno = 2000", "invcusth"); // will always select one row only
this.txtInvNo.DataBindings.Add("Text", ds, "invcusth.invno"); this.txtCustNo.DataBindings.Add("Text", ds, "invcusth.copk"); this.txtBiz.DataBindings.Add("Text", ds, "invcusth.bupk"); this.txtTrans.DataBindings.Add("Text", ds, "invcusth.transno"); this.dtDate.DataBindings.Add("Text", ds, "invcusth.invdate"); this.dtPaid.DataBindings.Add("Text", ds, "invcusth.paiddate"); }
After modifying the text fields, the following method is called:
private bool dataChange() { return ds.HasChanges(DataRowState.Modified); }
ALways returns false. I've used this method successfully with a DataGrid, but not with text boxes. Is ther any reason why it should not work/ or any alternative
Many thanks Mike Thomas
.NET Development9
|
|
|
|
|
CommonGenius.com
|
Posted: .NET Framework Data Access and Storage, Detecting Change in DataSet - Not Working |
Top |
When using databinding, you have to call EndEdit on the appropriate DataRow or DataRowView object before the values are moved from the Proposed state to the Current state, which is what changes the RowState to Modified.
|
|
|
|
|
Coleby
|
Posted: .NET Framework Data Access and Storage, Detecting Change in DataSet - Not Working |
Top |
I saw this post from a while back as I am having a similar problem with the rowstate in a grid that is not getting set to "Modified" unless I leave the row in the grid.
I'm not certain where to validate and the endedit method is not available for my table adapter.
Here's the code:
// Update unmatched tanks, facenames and shortcellname
foreach (TKData.sp_unmatched_inspRow rowCells in tblUnmatchedInspections)
{
if (rowCells.RowState == DataRowState.Modified)
{
//perform update to applicable tables
adapterUnmatchedInspections.UpdateQueryVFSIF001(rowCells.tankname, rowCells.tanknumber, rowCells.tanklocation, rowCells.ID);
// if (!rowCells.IsnewshortcellnameNull())
if(!string.IsNullOrEmpty(rowCells.newshortcellname.ToString()))
//Update VFSIF001_Cellfaces (Unmatched inspected cells)
adapterUnmatchedInspections.UpdateQueryVFSIF001_Cellfaces(rowCells.facename, rowCells.newshortcellname, rowCells.CFID);
else
{
adapterUnmatchedInspections.UpdateQueryVFSIF001_Cellfaces(rowCells.facename, rowCells.shortcellname, rowCells.CFID);
}
}
}
thanks
|
|
|
|
|
TilakGopi
|
Posted: .NET Framework Data Access and Storage, Detecting Change in DataSet - Not Working |
Top |
Hi,
posting in http://forums.asp.net/ for asp.net questions may help u getting the best answer.
Thanx,
Ch.T.Gopi Kumar.
|
|
|
|
|
Coleby
|
Posted: .NET Framework Data Access and Storage, Detecting Change in DataSet - Not Working |
Top |
thanks, but this is related to VS C#
|
|
|
|
|
Figo Fei - MSFT
|
Posted: .NET Framework Data Access and Storage, Detecting Change in DataSet - Not Working |
Top |
Hi, M Thomas
As far as I know, dataset in asp.net is different from the one in winform, dataset in asp.net have no modified status (nor added deleted etc.).
So the code you displayed is likely to work well in winform application but not work in asp.net.
That's the reason why ds.HasChanges() will always return false.
Thanks
|
|
|
|
|
Galin Iliev
|
Posted: .NET Framework Data Access and Storage, Detecting Change in DataSet - Not Working |
Top |
Hi Figo,
This is interesting. AFAIK there is only one DataSet class in .NET Framework classes and it resides in System.Data namespace in System.Data.dll.
this mean both Winform and Web application reference System.Data.dll and could create same dataset.
Regards,
|
|
|
|
|
Galin Iliev
|
Posted: .NET Framework Data Access and Storage, Detecting Change in DataSet - Not Working |
Top |
Hi Mike,
I suppose changing is fine as your databinging code looks good - default DataSourceUpdateMode is set to OnPropertyChange - as in your case.
The problem might be in the sequence of loading data into dataset.
I suppose you load data in Page_Load with happens on every page request - it doesnt matter if postback of first load
Although DataSet is same for Winforms and ASP.NET binging model is different. In ASP.NET you should load dataset on every page load - except when you cache it - which cause loosing state.
Take a look at these articles to understand it.
for proof you can change data in code as
ds["invcusth"].Rows[0]["transno"] = 11111;
and then check if there are changes. I am sure there will be
Hope this helps
|
|
|
|
|
Coleby
|
Posted: .NET Framework Data Access and Storage, Detecting Change in DataSet - Not Working |
Top |
foreach (TKData.sp_unmatched_inspRow rowCells in tblUnmatchedInspections)
{
Validate();
rowCells.EndEdit();
if (rowCells.RowState == DataRowState.Modified) // the state of the row here is still unchanged unless I actually leave the row in the grid.
{
//update stuff goes here
}
this is still doesn't seem to be working even when using the EndEdit method to end all editing on the rows in the datagrid.
Does anyone know a work around for this so that the RowState is "Modified"
thanks
|
|
|
|
|
Figo Fei - MSFT
|
Posted: .NET Framework Data Access and Storage, Detecting Change in DataSet - Not Working |
Top |
Hi, Galin
Yes, we can cache it as a solution, but it costs resources which is not necessary in a common situation.
However what I meant is that the method of utilizing dataset is somewhat different between asp.net and winform. In winform app dataset stored in the memory, while asp.net just push the data into the page and the dataset "dies" , unless you cache it.
Sorry for misunderstanding caused.
Thanks
|
|
|
|
|
|
|