473,401 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

HasChanges() returns incorrect value

I have a DataSet that contains all my data. From this DataSet, let's call it DS, I have 2 views that are based off of 2 seperate tables. We'll call them DataView History and DataView Info. I have a grid on my winForm that is dataBound to the Info view along with 2 combo boxes and 1 datetime picker. Everything works fine with these controls so that the filtering is done automatically by the grid. The other DataView, is bound to textboxes on another tab in my winForm. When I type information into these textboxes, change focus or leave focus, and try to click a button to that calls a save function that calls BindingContext[].EndCurrentEdit() for a tables in the DS. Then immediately after I check the DS to see if it has any changes by calling DS.HasChanges()... this function always returns false. If I debug my program, and pause it right at the HasChanges() step, i can check the following: DS.Tables["Info"].Rows[0]["address"] and I get the value that I entered into the textbox.

Why does the DS think that there is no changes to itself when I can clearly see that there is something there that wasn't before?

If I didn't give enough info, let me know... I'm still alittle new to this stuff
Jun 20 '07 #1
8 2122
nateraaaa
663 Expert 512MB
I have a DataSet that contains all my data. From this DataSet, let's call it DS, I have 2 views that are based off of 2 seperate tables. We'll call them DataView History and DataView Info. I have a grid on my winForm that is dataBound to the Info view along with 2 combo boxes and 1 datetime picker. Everything works fine with these controls so that the filtering is done automatically by the grid. The other DataView, is bound to textboxes on another tab in my winForm. When I type information into these textboxes, change focus or leave focus, and try to click a button to that calls a save function that calls BindingContext[].EndCurrentEdit() for a tables in the DS. Then immediately after I check the DS to see if it has any changes by calling DS.HasChanges()... this function always returns false. If I debug my program, and pause it right at the HasChanges() step, i can check the following: DS.Tables["Info"].Rows[0]["address"] and I get the value that I entered into the textbox.

Why does the DS think that there is no changes to itself when I can clearly see that there is something there that wasn't before?

If I didn't give enough info, let me know... I'm still alittle new to this stuff
Please look at this example.

Nathan
Jun 20 '07 #2
I looked at that example and called DS.GetChanges() and DS.GetChanges(DataRowState.Modified) and both returned null. I've also tried the following:

foreach(DataRow r in DS.Tables["Info"].Rows)
{
if(r["address"].RowState == DataRowState.Modified)
{
//debug here, even though it never gets here
}
}

so there seems to be no rows (atleast to the DS) that have had any changes...

thanks for the fast response!
Jun 20 '07 #3
nateraaaa
663 Expert 512MB
I looked at that example and called DS.GetChanges() and DS.GetChanges(DataRowState.Modified) and both returned null. I've also tried the following:

foreach(DataRow r in DS.Tables["Info"].Rows)
{
if(r["address"].RowState == DataRowState.Modified)
{
//debug here, even though it never gets here
}
}

so there seems to be no rows (atleast to the DS) that have had any changes...

thanks for the fast response!
I also found this example. Let us know if trying the code in this example works for you.

Nathan
Jun 20 '07 #4
yeah, i've run along this code out there and I'm nearly doing the same thing... I'm binding my textboxes with the following:

textBoxAddress1.DataBindings.Add("Text", _dependentsContactView, "contactinfo_address1");

and I've also tried:

textBoxAddress1.DataBindings.Add("Text", _dependentsContactView, "contactinfo_address1").ControlUpdateMode = ControlUpdateMode.OnPropertyChanged;

and also:

textBoxAddress1.DataBindings.Add("Text", _dependentsContactView, "contactinfo_address1").DataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged;

still no luck...I've tried now to debug the program when the TextChanged event is raised of my textbox. When I type something new in the text box (1 letter at a time) and debug the program and look at the DS.Tables["Info"].Rows[1]["address"] which has the original value, the rowstate for this row which is Unchanged, and the Text value of my textbox which as the new letter i typed. I just through in Row[1] because it just happens to be the row, for ease of debug use. But here's what I don't understand... when i click off of the textbox and back onto it again and type 1 more character, i enter into debug mode again. But this time, the DS contains the changes that the textbox had when it lost focus, ok, but the RowState is still Unchanged.... shouldn't the RowState have been updated since the data inside the row had been changed?
Jun 20 '07 #5
nateraaaa
663 Expert 512MB
yeah, i've run along this code out there and I'm nearly doing the same thing... I'm binding my textboxes with the following:

textBoxAddress1.DataBindings.Add("Text", _dependentsContactView, "contactinfo_address1");

and I've also tried:

textBoxAddress1.DataBindings.Add("Text", _dependentsContactView, "contactinfo_address1").ControlUpdateMode = ControlUpdateMode.OnPropertyChanged;

still no luck...I've tried now to debug the program when the TextChanged event is raised of my textbox. When I type something new in the text box (1 letter at a time) and debug the program and look at the DS.Tables["Info"].Rows[1]["address"] which has the original value, the rowstate for this row which is Unchanged, and the Text value of my textbox which as the new letter i typed. I just through in Row[1] because it just happens to be the row, for ease of debug use. But here's what I don't understand... when i click off of the textbox and back onto it again and type 1 more character, i enter into debug mode again. But this time, the DS contains the changes that the textbox had when it lost focus, ok, but the RowState is still Unchanged.... shouldn't the RowState have been updated since the data inside the row had been changed?
Are you calling the AcceptChanges method?
Jun 20 '07 #6
no, the AcceptChanges() will be called after the DS has been sent to the database and comes back
Jun 20 '07 #7
Well, I found a method that works, but I'm not sure how clean it is. On my databinding area, i set my text boxes to all be bound like the following:

textBoxAddress1.DataBindings.Add("Text", _dependentsContactView, "contactinfo_address1").DataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged;

I added the ".DataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged;" so that the user wouldn't have to click out of the textbox before clicking save.

But what I did in my save method is that I had to run through all all the rows in the view that I had created:

for (int i = 0; i < _dependentsContactView.Count; i++)
_dependentsContactView[i].EndEdit();

This modified the RowState of the correct rows to me "Modified" instead of "Unchanged". After this, I'm still running through all of my DS tables and calling EndCurrentEdit() on them. After that I'm checking to see if DS.HasChanges() is true (thank goodness it finally is, YEAH!!!) then I'm saving.

I was originally thinking that if I'm calling EndCurrentEdit() on the DS then that should work, but I have to EndEdit() first on the view based off of that table!

Thanks for all the help, I really appreciate it
Jun 20 '07 #8
nateraaaa
663 Expert 512MB
Well, I found a method that works, but I'm not sure how clean it is. On my databinding area, i set my text boxes to all be bound like the following:

textBoxAddress1.DataBindings.Add("Text", _dependentsContactView, "contactinfo_address1").DataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged;

I added the ".DataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged;" so that the user wouldn't have to click out of the textbox before clicking save.

But what I did in my save method is that I had to run through all all the rows in the view that I had created:

for (int i = 0; i < _dependentsContactView.Count; i++)
_dependentsContactView[i].EndEdit();

This modified the RowState of the correct rows to me "Modified" instead of "Unchanged". After this, I'm still running through all of my DS tables and calling EndCurrentEdit() on them. After that I'm checking to see if DS.HasChanges() is true (thank goodness it finally is, YEAH!!!) then I'm saving.

I was originally thinking that if I'm calling EndCurrentEdit() on the DS then that should work, but I have to EndEdit() first on the view based off of that table!

Thanks for all the help, I really appreciate it
Great. I am glad you were able to find a solution. Thank you for sharing.

Nathan
Jun 20 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Edward | last post by:
I have the following function to determine if a form is loaded: Public Function modIsloaded(ByVal vstrFormName As String) As Boolean ' Error handling removed for concision ' Determine if...
1
by: Jean Stax | last post by:
Hi ! I created a sample library project. In my second project I reference this library and make the following call, which returns "undefined value": Type myType =...
0
by: Michiel | last post by:
Hello, I'm trying to retrieve my cpu load as follows : PerformanceCounter* cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total"); float value =...
3
by: Stephan | last post by:
Hi, I'm working on a page with multiple Datalist-controls on it. The problem I'm facing is that when I try to update a record, the ItemIndex returns a value which is one lower than the Item I...
12
by: chellappa | last post by:
hi All, function automatically returns the value,am not used "return" i am using Linux -gcc complier please tell me.... what is problem... source ===== #include <stdio.h> main() {
2
by: nikolacace | last post by:
Hi, I have a stored procedure (the code is below) that I use to retrieve one value from my database. I tested the code in Query Analyzer, and it works (I get the value I was looking for). However,...
3
by: ApexData | last post by:
Hello I completed an application that worked great until I went to STARTUP and shut off all of the checkboxes. My code uses "Application.CurrentObjectName" to get the current Form name. All my...
1
by: `Zidane Tribal | last post by:
it would appear that using the command 'crc("data")' from the String::CRC returns incorrect results (although, they are at least consistently incorrect). for example, this script..... ...
13
by: mcfly1204 | last post by:
The following query only returns one value when several are expected. SELECT @contactid = Con.CONTACTID, @accountid = Con.ACCOUNTID, @lastname = LASTNAME, @firstname = FIRSTNAME, @email = EMAIL,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.