dataset and databindings

X

XmlAdoNewbie

Hi All,
I am new to c# .net and also new to ado .net and databindings. In my
application i create a dataset from an xml file and then databind the
values to controls on my form. An interesting thing happens when i
update the values on the form and i am wondering if i am doing
something wrong or if this how databindings works.

If i change the value of the control from within the control the
databinding updates the dataset as it should with no problems but if i
change the value of the control in code for instance TextBox1.text =
"Hello World"; it does not update the dataset and i actually have to
say ds.tables["mytable"].rows[0]["Column"] = "Hello World"; for it to
actually show up in the dataset. It seems to me that having to update
the dataset directly completely negates the reason i have used the
dataset in the first place... am i correct in saying this?? or am i
doing something wrong?

Thanks
Erin
 
C

Cor

Hi Erin,

You are probably doing something wrong.

Do you go before you check it

DirectCast(BindingContext(ds.Tables[0]), CurrencyManager).EndCurrentEdit();

(With the right table)

Cor
 
E

Erin Sebastian

Hi Cor,
No i don't do that actually so that might be something to try. I am
wondering though that if i set the text of the control in the code ie)
control.text = "hello world" should this automatically update the
dataset? or am i missing something here like the code snippet you have
just sent because if i update the dataset directly it works i just
didn't think i would have to update it directly since it is bound to the
control and changing the text property of the control should
automatically update the dataset???

if i change the text on the form side of things (directly in the
control) it works.

THanks
Erin
 
C

Cor

Hi Erin,

As far as I know is the dataset is updated when the textbox lostfocus so
when you make another textbox and go to that after enter, it should work
also.

Cor
 

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