dataset updates

N

Nisha

I am having a problem with my dataset update.
My form has the following:

A couple of text boxes and a listbox.

I have a strongly typed dataset on my form and dataadapter which has only an
Select / Update commands. Both the select and update commands have the
command.text property set to a stored proc. The select works nicely and
retrieves multiple rows in the listbox. As all the controls are bound to
columns within the same dataset, clicking on the listbox item scrolls to the
right row and the text boxes display the correct values. In short there is
no binding manager used... but the listbox does it automatically.

Below is the following code that is executed when I click on the save
button.

dim irow as integer = lisbox1.selectedindex
dim rowstatus = ds_regulatory.tables(0).rows(irow).rowstate()

At this point the value of rowstatus is "unchanged" although I am expecting
it to be "modified"

If ds_regulatory.haschanges() then
adapter_reg.Update(ds_regulatory)
endif


At this point when I check the sqlProfiler ( SQL tracking tool for MS
SQLServer), to see if the stored proc has gotten fired.... it hasn't because
the status of the row is unchanged.

Basically any changes made to the text box controls are reflected in the
dataset, but the rowstatus does not switch to "modified"

Any help or ideas ASAP would be appreciated. I am totally at my wits end.

Thanks in advance.

...Nisha
 
N

Nisha

Hi marina,

Thanks for your prompt response.

I am calling dataset.Acceptchanges method, but after the update... if the
update is successful then acceptchanges will change the row status to
unchanged.

...Nisha
 
M

Marina

If Update is successful, it would have called AcceptChanges for you, so your
second call would not do anything that didn't already happened.

It is hard to say what the problem is without the relevant code...
 
N

Nisha

Here is the code:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

'gets the current row in the listbox

Dim irow As Integer = ListBox1.SelectedIndex

'checks the rowstatus

Dim rowstatus = ds_regulatory.Tables(0).Rows(irow).RowState()

If ds_regulatory.haschanges() then

adapter_reg.Update(ds_regulatory)

ds_regulatory.acceptchanges()

endif

End Sub

Listbox1 & textbox1 & textbox2 have databindings to the typed dataset -
ds_regulatory in the design mode.

when the form retrieves the data... I change the value of textbox1.text and
textbox2.text and then click button1 which executes the code below.

At this point I am expecting to see my rowstatus:
(ds_regulatory.Tables(0).Rows(irow).RowState()) to be "Modified" as I have
made a change to the textbox and the textbox is bound to the dataset.
However the rowstatus remains "unchanged" and hence the update ofcourse does
not happen.

Any help in the right direction would be appreciated.

Thanks.
Nisha

@nospam.com> wrote in message
 
M

Marina

I guess I am used to databinding in webforms - but that's a one way
databind. The new data doesn't go back into the dataset, it has to be placed
there manually.
 
M

Miha Markic

Hi Nisha,

If you are using databinding there is always at least on bindingmanagerbase
out there.
You'll have to find it (depends on how you are doing databingind) and call
EndCurrentEdit method on it.
 
M

Miha Markic

Hi Marina,

Marina said:
If Update is successful, it would have called AcceptChanges for you, so your
second call would not do anything that didn't already happened.

Actually Update doesn't do anything to consolidate RowState.
AcceptChanges has to be called after successful update to consolidate the
rowstate (if there are no special requirements).
 
N

Nisha

So should I try using a bindingmanager or perhaps explicitly place the data
in the respective row / column in the dataset manually as you are
suggesting.

...Nisha
 
M

Marina

Actually, it is called.

If you read the documentation, you will see the steps taken:
1.. The values in the DataRow are moved to the parameter values.
2.. The OnRowUpdating event is raised.
3.. The command executes.
4.. If the command is set to FirstReturnedRecord, then the first returned
result is placed in the DataRow.
5.. If there are output parameters, they are placed in the DataRow.
6.. The OnRowUpdated event is raised.
7.. AcceptChanges is called.
Note that #7 is to call AcceptChanges, thus resetting the row state for
every row to unmodified.
 
N

Nisha

Hi Miha,

I have a typed dataset and am binding in the design mode of the form, the
respective columns of the dataset to the controls i.e textbox. Normally I
would have used the bindingmanager as I have done before. It takes care of
the navigation and with a little bit of code the textboxes and dataset are
in sync.

However this time around I have used a listbox and with absolutely no code
textboxes and dataset are in sync. All I have done is to bind a column
within the dataset to the listbox in design mode. And instead of providing
prev / next buttons on the form for the user to scroll the rows in the
dataset, I allow the user to select the column in the listbox and textboxes
being bound to the same dataset are in sync, and everything works real nice.

However if I change a value in any textbox... it is reflected in the
dataset... as I have put in some test code to see if the value I have typed
in the same as in the dataset.... and it is.

However the rowstate() property at this point should be "modified" but it
still remains at "unchanged". So I am really puzzled as to how the dataset
has the new values and has changed since the Fill was called.

As this is a readonly property, I cant manually change the value of the
rowstate. And if rowstate does not reflect correctly the update will never
go through.

Does the dataset perhaps have an updateable property or something which
makes it not updateable.
 
M

Miha Markic

Hi Nisha,

Nisha said:
Hi Miha,

I have a typed dataset and am binding in the design mode of the form, the
respective columns of the dataset to the controls i.e textbox. Normally I
would have used the bindingmanager as I have done before. It takes care of
the navigation and with a little bit of code the textboxes and dataset are
in sync.

However this time around I have used a listbox and with absolutely no code
textboxes and dataset are in sync. All I have done is to bind a column
within the dataset to the listbox in design mode. And instead of providing
prev / next buttons on the form for the user to scroll the rows in the
dataset, I allow the user to select the column in the listbox and textboxes
being bound to the same dataset are in sync, and everything works real
nice.

It doesn't matter how you bind data - there is always at least one
bindingmanager (the binding via designer just produces code in
"Windows Form Designer generated code region" for you.

And when you edit only one row data is always buffered by bindingmanager.

That's why you have to use EndCurrentEdit method.

However if I change a value in any textbox... it is reflected in the
dataset... as I have put in some test code to see if the value I have typed
in the same as in the dataset.... and it is.

Exactly how do you check?
However the rowstate() property at this point should be "modified" but it
still remains at "unchanged". So I am really puzzled as to how the dataset
has the new values and has changed since the Fill was called.

As this is a readonly property, I cant manually change the value of the
rowstate. And if rowstate does not reflect correctly the update will never
go through.
Yup.

Does the dataset perhaps have an updateable property or something which
makes it not updateable.

Only if column is marked as readonly.
 
N

Nisha

Hi Miha,

I appreciate your help. However I am still unsure of how to access the
default binding manager... Please see my response below:

Again thanks for your help...


Miha Markic said:
Hi Nisha,


nice.

It doesn't matter how you bind data - there is always at least one
bindingmanager (the binding via designer just produces code in
"Windows Form Designer generated code region" for you.

And when you edit only one row data is always buffered by bindingmanager.

That's why you have to use EndCurrentEdit method.

----------------------------------------------------

I found a simmilar reference to all the textbox bindings in the windows
generated code:

Me.tbx_accountno.DataBindings.Add(New System.Windows.Forms.Binding("Text",
Me.ds_regulatory, "sp_retrieve_regulatory.account_no"))

I am unsure of how to access the default binding manager. Please give me
some sample code if you have it...

Exactly how do you check?

-------------------------------------------------
I check the value with a simple line of code
Dim scct_no as string = ds_regulatory.tables(0).rows(0).item("account_no")

This reflects the new value typed in by me in the form.. but has not been
saved.
 
M

Miha Markic

Hi Nisha,

Try this:

Dim bmb as BindingManagerBase = textBox1.BindingContext[regulatory,
"sp_retrieve_regulatory"]

bmb.EndCurrentEdit()

It should change the RowState to modified.
 
N

Nisha

Hi Miha,

That worked perfectly. My row status is now modified and my update goes
through.

Thank you so much for your time and more so for resolving my problem.

...Nisha

Miha Markic said:
Hi Nisha,

Try this:

Dim bmb as BindingManagerBase = textBox1.BindingContext[regulatory,
"sp_retrieve_regulatory"]

bmb.EndCurrentEdit()

It should change the RowState to modified.


--
Miha Markic - RightHand .NET consulting & development
miha at rthand com
www.rhand.com

Nisha said:
Hi Miha,

I appreciate your help. However I am still unsure of how to access the
default binding manager... Please see my response below:

Again thanks for your help...


form,
the Normally care dataset
are no
code

----------------------------------------------------

I found a simmilar reference to all the textbox bindings in the windows
generated code:

Me.tbx_accountno.DataBindings.Add(New System.Windows.Forms.Binding("Text",
Me.ds_regulatory, "sp_retrieve_regulatory.account_no"))

I am unsure of how to access the default binding manager. Please give me
some sample code if you have it...



-------------------------------------------------
I check the value with a simple line of code
Dim scct_no as string = ds_regulatory.tables(0).rows(0).item("account_no")

This reflects the new value typed in by me in the form.. but has not been
saved.
but
it
 
N

Nisha

Hi Miha,

That worked perfectly. My row status is now modified and my update goes
through.

Thank you so much for your time and more so for resolving my problem.

...Nisha

Miha Markic said:
Hi Nisha,

Try this:

Dim bmb as BindingManagerBase = textBox1.BindingContext[regulatory,
"sp_retrieve_regulatory"]

bmb.EndCurrentEdit()

It should change the RowState to modified.


--
Miha Markic - RightHand .NET consulting & development
miha at rthand com
www.rhand.com

Nisha said:
Hi Miha,

I appreciate your help. However I am still unsure of how to access the
default binding manager... Please see my response below:

Again thanks for your help...


form,
the Normally care dataset
are no
code

----------------------------------------------------

I found a simmilar reference to all the textbox bindings in the windows
generated code:

Me.tbx_accountno.DataBindings.Add(New System.Windows.Forms.Binding("Text",
Me.ds_regulatory, "sp_retrieve_regulatory.account_no"))

I am unsure of how to access the default binding manager. Please give me
some sample code if you have it...



-------------------------------------------------
I check the value with a simple line of code
Dim scct_no as string = ds_regulatory.tables(0).rows(0).item("account_no")

This reflects the new value typed in by me in the form.. but has not been
saved.
but
it
 

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