SqlDataSource Update

Joined
Oct 25, 2006
Messages
6
Reaction score
0
Hello, I have searched high and low on the web for a "How to" on using the SqlDataSource Update method and I still cannot get my data to update in the database. Here is my code.

this.TARNetDateTimeFormView.DataBind();
TextBox localText = (TextBox)this.TARNetDateTimeFormView.Controls[0].FindControl("txtLoginDateTime");
localText.Text = DateTime.Now.ToString();
//this.TARNetDateTimeFormView.UpdateItem(false);
this.TARNetUsersSqlDataSource.UpdateParameters["LoginDateTime"].DefaultValue = DateTime.Now.ToString();
this.TARNetUsersSqlDataSource.Update();

The text box on the web page gets updated, but the data in the db does not. I also have the control on the FormView set to two-way data binding.

Thanks in advance for any suggestions! I've tried moving around that DataBind method, too.

Carolyn
 
Joined
Oct 25, 2006
Messages
6
Reaction score
0
SQLDataSource Update Solution

this.TARNetDateTimeFormView.DataBind();

TextBox localText = (TextBox)this.TARNetDateTimeFormView.
Controls[0].FindControl("txtLoginDateTime");

localText.Text = DateTime.UtcNow.ToString();

this.TARNetDateTimeFormView.UpdateItem(false);


And don't forget to set the DataKeyName property of the FormView to
the Primary Key in the database. This sample code will update the data
in the Form and in the DB. Just make sure the FormView DefaultMode is
set to Edit, too. Bind the DataSource property to the SQLDataSource
you created and with the above, that should be it.

Enjoy!
Carolyn
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top