470,573 Members | 1,619 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,573 developers. It's quick & easy.

DataSet update problem

I have created a very simple form with which I would like to update a
single
value in a single row of a database as a proof of concept.

The relevant parts of the form are a DBWebTextBox (which is hooked
into a
column ORGANISATION.SHORT_NAME) and a Button which I am using as a
submit
button.

I have the form updating the database correctly, but only after the
submit
button is clicked twice, which is not the intended behaviour for this
application.

I placed a break point within the OnClick method to see what is
happening, however the first time I click the button the event handler
is
never run, but I also have a DBWebNavigator control on my form and
that seems
to update correctly (allowing the Undo of the update) on the first
click, but
only on the second click does the event handler get run.

The event handler code is as follows...

private void btnSubmit_Click(object sender, System.EventArgs e)
{
int rowsUpdated;
bdpDataAdapter1.UpdateCommand.CommandText =
"UPDATE ORGANISATION SET SHORT_NAME = '" +
dbWebTextBox2.Text +
"' WHERE NAME = '" +
dbWebTextBox1.Text +
"'";

rowsUpdated = bdpDataAdapter1.Update(dataSet1);
bdpConnection1.Open();
bdpUpdateCommand1.ExecuteNonQuery();
bdpConnection1.Close();
dataSet1.AcceptChanges();
}

the only other event handler that I have is the Page_Load method,
however that does not have any code within it.

I was just wondering if I am missing anything in the order of
execution

Many thanks in advance
Nov 17 '05 #1
5 2878
alistair, do you have parameters or column mappings for your update
statement? Also, wtha's the purpose of calling Update and then
executenonquery? Finally, if your update works correctly, acceptchanges
gets called on each row as it's updated so that's not necessary.

Very that your dataset HasChanges() first to make sure that there's
something to update, then we'll work on the update command.

BTW, paramaterize that query regardless - there's all downside to not using
parameters.
"Alastair Anderson" <al***************@hotmail.com> wrote in message
news:af**************************@posting.google.c om...
I have created a very simple form with which I would like to update a
single
value in a single row of a database as a proof of concept.

The relevant parts of the form are a DBWebTextBox (which is hooked
into a
column ORGANISATION.SHORT_NAME) and a Button which I am using as a
submit
button.

I have the form updating the database correctly, but only after the
submit
button is clicked twice, which is not the intended behaviour for this
application.

I placed a break point within the OnClick method to see what is
happening, however the first time I click the button the event handler
is
never run, but I also have a DBWebNavigator control on my form and
that seems
to update correctly (allowing the Undo of the update) on the first
click, but
only on the second click does the event handler get run.

The event handler code is as follows...

private void btnSubmit_Click(object sender, System.EventArgs e)
{
int rowsUpdated;
bdpDataAdapter1.UpdateCommand.CommandText =
"UPDATE ORGANISATION SET SHORT_NAME = '" +
dbWebTextBox2.Text +
"' WHERE NAME = '" +
dbWebTextBox1.Text +
"'";

rowsUpdated = bdpDataAdapter1.Update(dataSet1);
bdpConnection1.Open();
bdpUpdateCommand1.ExecuteNonQuery();
bdpConnection1.Close();
dataSet1.AcceptChanges();
}

the only other event handler that I have is the Page_Load method,
however that does not have any code within it.

I was just wondering if I am missing anything in the order of
execution

Many thanks in advance

Nov 17 '05 #2
> I placed a break point within the OnClick method to see what is
happening, however the first time I click the button the event handler
is never run
It doesn't sound like a DB issue to me. It sounds like a post-back issue (i'm assuming this is a web form).

Is "Button" a custom type or a System.Web.UI.WebControls.Button?

Either way, the "click" event should be hooked up in the OnLoad method.

--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
"W.G. Ryan MVP" <Wi*********@nospam.gmail.com> wrote in message news:%2******************@TK2MSFTNGP09.phx.gbl... alistair, do you have parameters or column mappings for your update statement? Also, wtha's the purpose of calling Update and
then executenonquery? Finally, if your update works correctly, acceptchanges gets called on each row as it's updated so that's
not necessary.

Very that your dataset HasChanges() first to make sure that there's something to update, then we'll work on the update command.

BTW, paramaterize that query regardless - there's all downside to not using parameters.
"Alastair Anderson" <al***************@hotmail.com> wrote in message news:af**************************@posting.google.c om...
I have created a very simple form with which I would like to update a
single
value in a single row of a database as a proof of concept.

The relevant parts of the form are a DBWebTextBox (which is hooked
into a
column ORGANISATION.SHORT_NAME) and a Button which I am using as a
submit
button.

I have the form updating the database correctly, but only after the
submit
button is clicked twice, which is not the intended behaviour for this
application.

I placed a break point within the OnClick method to see what is
happening, however the first time I click the button the event handler
is
never run, but I also have a DBWebNavigator control on my form and
that seems
to update correctly (allowing the Undo of the update) on the first
click, but
only on the second click does the event handler get run.

The event handler code is as follows...

private void btnSubmit_Click(object sender, System.EventArgs e)
{
int rowsUpdated;
bdpDataAdapter1.UpdateCommand.CommandText =
"UPDATE ORGANISATION SET SHORT_NAME = '" +
dbWebTextBox2.Text +
"' WHERE NAME = '" +
dbWebTextBox1.Text +
"'";

rowsUpdated = bdpDataAdapter1.Update(dataSet1);
bdpConnection1.Open();
bdpUpdateCommand1.ExecuteNonQuery();
bdpConnection1.Close();
dataSet1.AcceptChanges();
}

the only other event handler that I have is the Page_Load method,
however that does not have any code within it.

I was just wondering if I am missing anything in the order of
execution

Many thanks in advance


Nov 17 '05 #3
Thanks for your input William,

"W.G. Ryan MVP" <Wi*********@nospam.gmail.com> wrote in message news:<#G**************@TK2MSFTNGP09.phx.gbl>...
alistair, do you have parameters or column mappings for your update
statement?
I do not have any parameters or column mappings
for the update, the piece of code that is listed is not going to be
the final
code in terms of SQL, as I understand the importance of parameterising
it.
Also, wtha's the purpose of calling Update and then
executenonquery?
I am totally new to this side of database development, I have used the
client dataset and data provider methods that are used within Delphi
and C# data modules, so my thinking at the time of posting this could
be wrong, but re-reading the code it looks like it is doing the same
thing as I have set the UpdateCommand of the DataAdapter to be the
bdpUpdateCommand, and I am guessing that calling Update and
ExecuteNonQuery do the same thing?
Finally, if your update works correctly, acceptchanges
gets called on each row as it's updated so that's not necessary.

Very that your dataset HasChanges() first to make sure that there's
something to update, then we'll work on the update command.
Again similar to the parameterised query issue, I realise the
inefficiency in this and will optimise it once I get the messy version
working :-), but other than my initial misunderstanding of
ExecuteNonQuery and Update, would these affect the need to click the
button twice for submitting data, as would these not be executed no
matter how inefficent the logic is?
BTW, paramaterize that query regardless - there's all downside to not using
parameters.
"Alastair Anderson" <al***************@hotmail.com> wrote in message
news:af**************************@posting.google.c om...
I have created a very simple form with which I would like to update a
single
value in a single row of a database as a proof of concept.

The relevant parts of the form are a DBWebTextBox (which is hooked
into a
column ORGANISATION.SHORT_NAME) and a Button which I am using as a
submit
button.

I have the form updating the database correctly, but only after the
submit
button is clicked twice, which is not the intended behaviour for this
application.

I placed a break point within the OnClick method to see what is
happening, however the first time I click the button the event handler
is
never run, but I also have a DBWebNavigator control on my form and
that seems
to update correctly (allowing the Undo of the update) on the first
click, but
only on the second click does the event handler get run.

The event handler code is as follows...

private void btnSubmit_Click(object sender, System.EventArgs e)
{
int rowsUpdated;
bdpDataAdapter1.UpdateCommand.CommandText =
"UPDATE ORGANISATION SET SHORT_NAME = '" +
dbWebTextBox2.Text +
"' WHERE NAME = '" +
dbWebTextBox1.Text +
"'";

rowsUpdated = bdpDataAdapter1.Update(dataSet1);
bdpConnection1.Open();
bdpUpdateCommand1.ExecuteNonQuery();
bdpConnection1.Close();
dataSet1.AcceptChanges();
}

the only other event handler that I have is the Page_Load method,
however that does not have any code within it.

I was just wondering if I am missing anything in the order of
execution

Many thanks in advance

Nov 17 '05 #4
Hi Dave,
The button is of type System.Web.UI.WebControls.Button and I have now
changed the OnClick event to be "hooked" up within the Page_Load
method and the behaviour is still the same, two clicks before the
OnClick event is even fired.

Which I agree sounds like a post back issue but I am still stumped as
to what.

"Dave" <NO*********@dotcomdatasolutions.com> wrote in message news:<#s*************@TK2MSFTNGP12.phx.gbl>...
I placed a break point within the OnClick method to see what is
happening, however the first time I click the button the event handler
is never run


It doesn't sound like a DB issue to me. It sounds like a post-back issue (i'm assuming this is a web form).

Is "Button" a custom type or a System.Web.UI.WebControls.Button?

Either way, the "click" event should be hooked up in the OnLoad method.

--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
"W.G. Ryan MVP" <Wi*********@nospam.gmail.com> wrote in message news:%2******************@TK2MSFTNGP09.phx.gbl...
alistair, do you have parameters or column mappings for your update statement? Also, wtha's the purpose of calling Update and
then executenonquery? Finally, if your update works correctly, acceptchanges gets called on each row as it's updated so that's
not necessary.

Very that your dataset HasChanges() first to make sure that there's something to update, then we'll work on the update command.

BTW, paramaterize that query regardless - there's all downside to not using parameters.
"Alastair Anderson" <al***************@hotmail.com> wrote in message news:af**************************@posting.google.c om...
I have created a very simple form with which I would like to update a
single
value in a single row of a database as a proof of concept.

The relevant parts of the form are a DBWebTextBox (which is hooked
into a
column ORGANISATION.SHORT_NAME) and a Button which I am using as a
submit
button.

I have the form updating the database correctly, but only after the
submit
button is clicked twice, which is not the intended behaviour for this
application.

I placed a break point within the OnClick method to see what is
happening, however the first time I click the button the event handler
is
never run, but I also have a DBWebNavigator control on my form and
that seems
to update correctly (allowing the Undo of the update) on the first
click, but
only on the second click does the event handler get run.

The event handler code is as follows...

private void btnSubmit_Click(object sender, System.EventArgs e)
{
int rowsUpdated;
bdpDataAdapter1.UpdateCommand.CommandText =
"UPDATE ORGANISATION SET SHORT_NAME = '" +
dbWebTextBox2.Text +
"' WHERE NAME = '" +
dbWebTextBox1.Text +
"'";

rowsUpdated = bdpDataAdapter1.Update(dataSet1);
bdpConnection1.Open();
bdpUpdateCommand1.ExecuteNonQuery();
bdpConnection1.Close();
dataSet1.AcceptChanges();
}

the only other event handler that I have is the Page_Load method,
however that does not have any code within it.

I was just wondering if I am missing anything in the order of
execution

Many thanks in advance


Nov 17 '05 #5
That does sound strange, but nothing that I haven't experienced :)

It's tough for me to say what the issue is without seeing the code, but I can suggest a couple of possiblities:

1. Make sure that you are checking that Page.IsPostBack returns false when initializing variables to their default values. Not
checking this property is a common mistake which can lead to bugs like yours. You may be reinitializing your variables every time
the page loads (even upon a postback) which can cause the "state" of your app to be invalid. This differs from initialization which
MUST occur prior to the Page.Load event, for instance in a DataGrid Control.

2. All Control-fired event handlers must be hooked-up on, or before the Page.Load event occurs otherwise they will not be invoked by
the Page or it's Controls.

3. Make sure that all Controls (added without the aid of the designer) are part of the Page.Controls collection on, or before the
Page.Init event.
GL

--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
"Alastair Anderson" <al***************@hotmail.com> wrote in message news:af**************************@posting.google.c om...
Hi Dave,
The button is of type System.Web.UI.WebControls.Button and I have now
changed the OnClick event to be "hooked" up within the Page_Load
method and the behaviour is still the same, two clicks before the
OnClick event is even fired.

Which I agree sounds like a post back issue but I am still stumped as
to what.

"Dave" <NO*********@dotcomdatasolutions.com> wrote in message news:<#s*************@TK2MSFTNGP12.phx.gbl>...
> I placed a break point within the OnClick method to see what is
> happening, however the first time I click the button the event handler
> is never run


It doesn't sound like a DB issue to me. It sounds like a post-back issue (i'm assuming this is a web form).

Is "Button" a custom type or a System.Web.UI.WebControls.Button?

Either way, the "click" event should be hooked up in the OnLoad method.

--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
"W.G. Ryan MVP" <Wi*********@nospam.gmail.com> wrote in message news:%2******************@TK2MSFTNGP09.phx.gbl...
> alistair, do you have parameters or column mappings for your update statement? Also, wtha's the purpose of calling Update and
> then executenonquery? Finally, if your update works correctly, acceptchanges gets called on each row as it's updated so
> that's
> not necessary.
>
> Very that your dataset HasChanges() first to make sure that there's something to update, then we'll work on the update command.
>
> BTW, paramaterize that query regardless - there's all downside to not using parameters.
> "Alastair Anderson" <al***************@hotmail.com> wrote in message news:af**************************@posting.google.c om...
>>I have created a very simple form with which I would like to update a
>> single
>> value in a single row of a database as a proof of concept.
>>
>> The relevant parts of the form are a DBWebTextBox (which is hooked
>> into a
>> column ORGANISATION.SHORT_NAME) and a Button which I am using as a
>> submit
>> button.
>>
>> I have the form updating the database correctly, but only after the
>> submit
>> button is clicked twice, which is not the intended behaviour for this
>> application.
>>
>> I placed a break point within the OnClick method to see what is
>> happening, however the first time I click the button the event handler
>> is
>> never run, but I also have a DBWebNavigator control on my form and
>> that seems
>> to update correctly (allowing the Undo of the update) on the first
>> click, but
>> only on the second click does the event handler get run.
>>
>> The event handler code is as follows...
>>
>> private void btnSubmit_Click(object sender, System.EventArgs e)
>> {
>> int rowsUpdated;
>> bdpDataAdapter1.UpdateCommand.CommandText =
>> "UPDATE ORGANISATION SET SHORT_NAME = '" +
>> dbWebTextBox2.Text +
>> "' WHERE NAME = '" +
>> dbWebTextBox1.Text +
>> "'";
>>
>> rowsUpdated = bdpDataAdapter1.Update(dataSet1);
>> bdpConnection1.Open();
>> bdpUpdateCommand1.ExecuteNonQuery();
>> bdpConnection1.Close();
>> dataSet1.AcceptChanges();
>> }
>>
>> the only other event handler that I have is the Page_Load method,
>> however that does not have any code within it.
>>
>> I was just wondering if I am missing anything in the order of
>> execution
>>
>> Many thanks in advance
>
>

Nov 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Bruce Stockwell | last post: by
7 posts views Thread by Zachary Hilbun | last post: by
15 posts views Thread by JIM.H. | last post: by
4 posts views Thread by jay | last post: by
12 posts views Thread by Graham Blandford | last post: by
4 posts views Thread by Al | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.