PC Review


Reply
Thread Tools Rate Thread

Dataset doesn't return true when dataset datarow has been modified

 
 
=?Utf-8?B?QWxwaGE=?=
Guest
Posts: n/a
 
      2nd Nov 2005
Hi, I have a window C# application. I update the dataset when user finished
entering in a text box. But when I want to update the database when OK is
pressed, the if(dsVehicle.HasChanges(DataRowState.Modified)) would return
false and update of the dataset would take place. I do notice that if I
select other item that the textbox is bind to then the modified indicator
would then return true. Is there any code that I can add in the private void
txtVYear_Validated(object sender, System.EventArgs e) to indicate the dataset
row has been changed myself?

Thanks, Alpha

cmbScheudle.DataSource = dsSchedule.Tables["Schedule"];
cmbScheudle.DisplayMember = "ScheduleName";
cmbScheudle.ValueMember = "SchID";

//bind all the editable textboxes
cmbScheudle.DataBindings.Add("SelectedValue", dsVehicle.Tables["VehDetail"],
"ExtSchID");
txtVName.DataBindings.Add("Text", dsVehicle.Tables["VehDetail"], "VName");
txtVIN.DataBindings.Add("Text", dsVehicle.Tables["VehDetail"], "VIN");
txtVYear.DataBindings.Add("Text", dsVehicle.Tables["VehDetail"], "Year");
txtVMaker.DataBindings.Add("Text", dsVehicle.Tables["VehDetail"], "Make");
txtVModel.DataBindings.Add("Text", dsVehicle.Tables["VehDetail"], "Model");
txtDMV.DataBindings.Add("Text", dsVehicle.Tables["VehDetail"], "DMVLicense");
dtpDMVExp.DataBindings.Add("VALUE", dsVehicle.Tables["VehDetail"],
"DMVExpirationDate");
txtDOTReg.DataBindings.Add("Text", dsVehicle.Tables["VehDetail"],
"DOTRegistration");
dtpDOTExp.DataBindings.Add("VALUE", dsVehicle.Tables["VehDetail"],
"DOTExpirationDate");
VListing.CurrentRowIndex = 0;


{
if ((!Loading) && (txtVYear.Text.Length>0))
dsVehicle.Tables["VehDetail"].Rows[VListing.CurrentRowIndex]["Year"] =
txtVYear.Text.ToString();
}

private void btnOK_Click(object sender, System.EventArgs e)
{
if(dsVehicle.HasChanges(DataRowState.Modified))
{
conVeh.Open();
sdaVehicle.Update(dsVehicle, "VehDetail");
conVeh.Close();
}
SaveMsg = false;
this.Close();
}
 
Reply With Quote
 
 
 
 
Pete Davis
Guest
Posts: n/a
 
      3rd Nov 2005
I think all you need to do is call CurrencyManager.EndCurrentEdit() prior to
doing the HasChanged check.

You'd basically do:

BindingContext[cmbScheudle.DataSource].EndCurrentEdit();

You may have to do it for the individual PropertyManager for the particular
TextBox that last had the focus. I'm not sure. I'm really just taking a stab
in the dark here. I haven't done much with binding controls other than grid
style controls.

I'm not positive your changes will get pushed to the dataset prior to the
EndCurrentEdit, though. Anyway, give these a try and if neither of these
work, I'll try to come up with another option.

Pete

"Alpha" <(E-Mail Removed)> wrote in message
news:73A49146-79BD-44C4-9B5E-(E-Mail Removed)...
> Hi, I have a window C# application. I update the dataset when user
> finished
> entering in a text box. But when I want to update the database when OK is
> pressed, the if(dsVehicle.HasChanges(DataRowState.Modified)) would return
> false and update of the dataset would take place. I do notice that if I
> select other item that the textbox is bind to then the modified indicator
> would then return true. Is there any code that I can add in the private
> void
> txtVYear_Validated(object sender, System.EventArgs e) to indicate the
> dataset
> row has been changed myself?
>
> Thanks, Alpha
>
> cmbScheudle.DataSource = dsSchedule.Tables["Schedule"];
> cmbScheudle.DisplayMember = "ScheduleName";
> cmbScheudle.ValueMember = "SchID";
>
> //bind all the editable textboxes
> cmbScheudle.DataBindings.Add("SelectedValue",
> dsVehicle.Tables["VehDetail"],
> "ExtSchID");
> txtVName.DataBindings.Add("Text", dsVehicle.Tables["VehDetail"], "VName");
> txtVIN.DataBindings.Add("Text", dsVehicle.Tables["VehDetail"], "VIN");
> txtVYear.DataBindings.Add("Text", dsVehicle.Tables["VehDetail"], "Year");
> txtVMaker.DataBindings.Add("Text", dsVehicle.Tables["VehDetail"], "Make");
> txtVModel.DataBindings.Add("Text", dsVehicle.Tables["VehDetail"],
> "Model");
> txtDMV.DataBindings.Add("Text", dsVehicle.Tables["VehDetail"],
> "DMVLicense");
> dtpDMVExp.DataBindings.Add("VALUE", dsVehicle.Tables["VehDetail"],
> "DMVExpirationDate");
> txtDOTReg.DataBindings.Add("Text", dsVehicle.Tables["VehDetail"],
> "DOTRegistration");
> dtpDOTExp.DataBindings.Add("VALUE", dsVehicle.Tables["VehDetail"],
> "DOTExpirationDate");
> VListing.CurrentRowIndex = 0;
>
>
> {
> if ((!Loading) && (txtVYear.Text.Length>0))
> dsVehicle.Tables["VehDetail"].Rows[VListing.CurrentRowIndex]["Year"] =
> txtVYear.Text.ToString();
> }
>
> private void btnOK_Click(object sender, System.EventArgs e)
> {
> if(dsVehicle.HasChanges(DataRowState.Modified))
> {
> conVeh.Open();
> sdaVehicle.Update(dsVehicle, "VehDetail");
> conVeh.Close();
> }
> SaveMsg = false;
> this.Close();
> }



 
Reply With Quote
 
 
 
 
=?Utf-8?B?QWxwaGE=?=
Guest
Posts: n/a
 
      3rd Nov 2005
Hi Pete, thank you for your reply. I noticed that it does save the
modification to the dataset if I click on another row on the datagrid which
the textbox is bind to. So I did the following code and it works. It's not
pretty but I tigger the datagrid selection row change event and it then
records the textbox changes to the dataset. Strange and not pretty but it
works for now. I would still like to find a better and more elegant way to
do this thougth.

private void txtVYear_Validated(object sender, System.EventArgs e)
{
if ((!Loading) && (txtVYear.Text.Length>0))
{
int curRow = VListing.CurrentRowIndex;
DataRow dr = dsVehicle.Tables["VehDetail"].Rows[VListing.CurrentRowIndex];
dr["Year"] = txtVYear.Text.ToString();
VListing.CurrentRowIndex = curRow;
}
}

"Pete Davis" wrote:

> I think all you need to do is call CurrencyManager.EndCurrentEdit() prior to
> doing the HasChanged check.
>
> You'd basically do:
>
> BindingContext[cmbScheudle.DataSource].EndCurrentEdit();
>
> You may have to do it for the individual PropertyManager for the particular
> TextBox that last had the focus. I'm not sure. I'm really just taking a stab
> in the dark here. I haven't done much with binding controls other than grid
> style controls.
>
> I'm not positive your changes will get pushed to the dataset prior to the
> EndCurrentEdit, though. Anyway, give these a try and if neither of these
> work, I'll try to come up with another option.
>
> Pete
>
> "Alpha" <(E-Mail Removed)> wrote in message
> news:73A49146-79BD-44C4-9B5E-(E-Mail Removed)...
> > Hi, I have a window C# application. I update the dataset when user
> > finished
> > entering in a text box. But when I want to update the database when OK is
> > pressed, the if(dsVehicle.HasChanges(DataRowState.Modified)) would return
> > false and update of the dataset would take place. I do notice that if I
> > select other item that the textbox is bind to then the modified indicator
> > would then return true. Is there any code that I can add in the private
> > void
> > txtVYear_Validated(object sender, System.EventArgs e) to indicate the
> > dataset
> > row has been changed myself?
> >
> > Thanks, Alpha
> >
> > cmbScheudle.DataSource = dsSchedule.Tables["Schedule"];
> > cmbScheudle.DisplayMember = "ScheduleName";
> > cmbScheudle.ValueMember = "SchID";
> >
> > //bind all the editable textboxes
> > cmbScheudle.DataBindings.Add("SelectedValue",
> > dsVehicle.Tables["VehDetail"],
> > "ExtSchID");
> > txtVName.DataBindings.Add("Text", dsVehicle.Tables["VehDetail"], "VName");
> > txtVIN.DataBindings.Add("Text", dsVehicle.Tables["VehDetail"], "VIN");
> > txtVYear.DataBindings.Add("Text", dsVehicle.Tables["VehDetail"], "Year");
> > txtVMaker.DataBindings.Add("Text", dsVehicle.Tables["VehDetail"], "Make");
> > txtVModel.DataBindings.Add("Text", dsVehicle.Tables["VehDetail"],
> > "Model");
> > txtDMV.DataBindings.Add("Text", dsVehicle.Tables["VehDetail"],
> > "DMVLicense");
> > dtpDMVExp.DataBindings.Add("VALUE", dsVehicle.Tables["VehDetail"],
> > "DMVExpirationDate");
> > txtDOTReg.DataBindings.Add("Text", dsVehicle.Tables["VehDetail"],
> > "DOTRegistration");
> > dtpDOTExp.DataBindings.Add("VALUE", dsVehicle.Tables["VehDetail"],
> > "DOTExpirationDate");
> > VListing.CurrentRowIndex = 0;
> >
> >
> > {
> > if ((!Loading) && (txtVYear.Text.Length>0))
> > dsVehicle.Tables["VehDetail"].Rows[VListing.CurrentRowIndex]["Year"] =
> > txtVYear.Text.ToString();
> > }
> >
> > private void btnOK_Click(object sender, System.EventArgs e)
> > {
> > if(dsVehicle.HasChanges(DataRowState.Modified))
> > {
> > conVeh.Open();
> > sdaVehicle.Update(dsVehicle, "VehDetail");
> > conVeh.Close();
> > }
> > SaveMsg = false;
> > this.Close();
> > }

>
>
>

 
Reply With Quote
 
=?Utf-8?B?QWxwaGE=?=
Guest
Posts: n/a
 
      11th Nov 2005
I just ried using what you suggested in my other part of the code and it
worked great too. Thanks again.

Allpha

"Pete Davis" wrote:

> I think all you need to do is call CurrencyManager.EndCurrentEdit() prior to
> doing the HasChanged check.
>
> You'd basically do:
>
> BindingContext[cmbScheudle.DataSource].EndCurrentEdit();
>
> You may have to do it for the individual PropertyManager for the particular
> TextBox that last had the focus. I'm not sure. I'm really just taking a stab
> in the dark here. I haven't done much with binding controls other than grid
> style controls.
>
> I'm not positive your changes will get pushed to the dataset prior to the
> EndCurrentEdit, though. Anyway, give these a try and if neither of these
> work, I'll try to come up with another option.
>
> Pete
>
> "Alpha" <(E-Mail Removed)> wrote in message
> news:73A49146-79BD-44C4-9B5E-(E-Mail Removed)...
> > Hi, I have a window C# application. I update the dataset when user
> > finished
> > entering in a text box. But when I want to update the database when OK is
> > pressed, the if(dsVehicle.HasChanges(DataRowState.Modified)) would return
> > false and update of the dataset would take place. I do notice that if I
> > select other item that the textbox is bind to then the modified indicator
> > would then return true. Is there any code that I can add in the private
> > void
> > txtVYear_Validated(object sender, System.EventArgs e) to indicate the
> > dataset
> > row has been changed myself?
> >
> > Thanks, Alpha
> >
> > cmbScheudle.DataSource = dsSchedule.Tables["Schedule"];
> > cmbScheudle.DisplayMember = "ScheduleName";
> > cmbScheudle.ValueMember = "SchID";
> >
> > //bind all the editable textboxes
> > cmbScheudle.DataBindings.Add("SelectedValue",
> > dsVehicle.Tables["VehDetail"],
> > "ExtSchID");
> > txtVName.DataBindings.Add("Text", dsVehicle.Tables["VehDetail"], "VName");
> > txtVIN.DataBindings.Add("Text", dsVehicle.Tables["VehDetail"], "VIN");
> > txtVYear.DataBindings.Add("Text", dsVehicle.Tables["VehDetail"], "Year");
> > txtVMaker.DataBindings.Add("Text", dsVehicle.Tables["VehDetail"], "Make");
> > txtVModel.DataBindings.Add("Text", dsVehicle.Tables["VehDetail"],
> > "Model");
> > txtDMV.DataBindings.Add("Text", dsVehicle.Tables["VehDetail"],
> > "DMVLicense");
> > dtpDMVExp.DataBindings.Add("VALUE", dsVehicle.Tables["VehDetail"],
> > "DMVExpirationDate");
> > txtDOTReg.DataBindings.Add("Text", dsVehicle.Tables["VehDetail"],
> > "DOTRegistration");
> > dtpDOTExp.DataBindings.Add("VALUE", dsVehicle.Tables["VehDetail"],
> > "DOTExpirationDate");
> > VListing.CurrentRowIndex = 0;
> >
> >
> > {
> > if ((!Loading) && (txtVYear.Text.Length>0))
> > dsVehicle.Tables["VehDetail"].Rows[VListing.CurrentRowIndex]["Year"] =
> > txtVYear.Text.ToString();
> > }
> >
> > private void btnOK_Click(object sender, System.EventArgs e)
> > {
> > if(dsVehicle.HasChanges(DataRowState.Modified))
> > {
> > conVeh.Open();
> > sdaVehicle.Update(dsVehicle, "VehDetail");
> > conVeh.Close();
> > }
> > SaveMsg = false;
> > this.Close();
> > }

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is DataRow[string] uses DataRow[int] and DataRow[int] much efficient than DataRow[string]? Ryan Liu Microsoft C# .NET 3 2nd Feb 2008 07:14 AM
Do not let user save template if it has been been modified Maddoktor Microsoft Excel Programming 1 18th Jan 2007 12:49 AM
TRUE and TRUE or TRUE then...... Susan Microsoft Excel Programming 3 1st Nov 2006 08:31 PM
Process.ExitCode returns InvalidOperationException when starting process with RedirectStandardInput = true, RedirectStandardError = true, RedirectStandardOutput = true; SMichal Microsoft Dot NET Framework 0 8th Sep 2006 07:28 AM
How to know if DataSet has been modified since last fill? XIA Chengbin Microsoft ADO .NET 1 22nd Jul 2003 09:08 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:45 AM.