posting to SQL

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, I'm sure this is a standard thing. I have a web form with several input
boxes/drop down lists and checkboxes. They all represent a field within a sql
table and I need the user to update the values on hitting submit. I have put
a submit button on the form and tested it with one field, so in the submit
code I opened a sql connection and did an UPDATE mytable SET fieldintable =
inputonwebform.text where customerid=x.

This worked! However, it just so happened that I changed the value in
'fieldontable'. Should I be creating an update statement for EVERY field on
my form, even though the user may only change one or two values at a time? I
know there is a OnTextChanged event handler of a text box, so i could capture
whether it has been changed or not (and then have to handle the drop
downs/checkboxes too presumbably using a different handler), but how can I
maintain a list of controls whose values have changed up until the point
where the user hits submit. Looking for the best practice to do this. dont
want to start keeping a comma seperated value in a hidden field, I find that
really messy. I am sure there is a really good way to do this as this seems
to be the power of web forms, I just need someone to tell me it!!!

Many thanks.
 
Well personally I use a different technique to update my sql database. I
just write out my sql scripts manually.

for instance:

On_Submit_Click() {
string sql = "update Customers set LoginID='" + txtLoginID.Text + "',
Password='" + txtPassword.Text "' where CustomerID=" + lblCustomerID.Text;

SqlConnection con = new SqlConnection("connection string");
SqlCommand com = new SqlCommand(sql, con);

con.Open();
com.ExecuteNonQuery();
con.close();
}

I know this style is kind of old school but to me it just seems like you can
customize your sql scripts even more and thus allow for more complicated and
userfriendly forms.

As for how this applies to your problem... it's quite simple. All fields
are always updated with one sql statement if they haven't changed they are
just set to whatever they used to be if they have changed then they are
updated.

This method should be considerably faster to execute and less processor
intensive for both your ASP.NET applicaiton and the SQL Server.

These are just my thoughts on the subject.

Cheers!

David Kyle
www.chloemag.com
 
Back
Top