Call

VB.NET Code Snippets: Updating a data source using an event

Filed under ASP.NET, Microsoft

You may wish to update a data source using an event.

'You need to use FindControl to access control on a  FormView:
Dim FirstName As TextBox = FormView1.FindControl("FirstNameTextBox")
Dim LastName As TextBox = FormView1.FindControl("LastNameTextBox")
Dim Phone As TextBox = FormView1.FindControl("PhoneTextBox")
Dim Email As TextBox = FormView1.FindControl("EmailTextBox")
SqlDataSource1.InsertParameters("FirstName").DefaultValue = FirstName
SqlDataSource1.InsertParameters("LastName").DefaultValue = LastName
SqlDataSource1.InsertParameters("Phone").DefaultValue = Phone
SqlDataSource1.InsertParameters("Email").DefaultValue = Email
SqlDataSource1.Insert()

And, this is the code for Update:

SqlDataSource1.UpdateParameters("FirstName").DefaultValue = FirstName
SqlDataSource1.UpdateParameters("LastName").DefaultValue = LastName
SqlDataSource1.UpdateParameters("Phone").DefaultValue = Phone
SqlDataSource1.UpdateParameters("Email").DefaultValue = Email
SqlDataSource1. Update()


Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*