Programmatically Update SqlDataSource
-
I need to update a column of a record. I am using a FormView control to provide the UI for the SqlDataSource. The update method MUST be called from a button, rather than the built in "Update" feature of FormView1_ItemCommand, (unless there is a way to call this event with a command on the button control.) I am attempting the SqlDataSource update by: Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click SqlDataSource1.Update() End Sub and: Protected Sub SqlDataSource1_Updating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceCommandEventArgs) Handles SqlDataSource1.Updating Dim totalcost As Single = 400 e.Command.Parameters("@TotalCost").Value = totalcost 'SqlDataSource1.UpdateParameters("TotalCost").DefaultValue = totalcost End Sub Neither the e.Command.Parameters("@TotalCost").Value = totalcost or the SqlDataSource1.UpdateParameters("TotalCost").DefaultValue = totalcost has any impact. Any help would be greatly appreciated....thank you
-
I need to update a column of a record. I am using a FormView control to provide the UI for the SqlDataSource. The update method MUST be called from a button, rather than the built in "Update" feature of FormView1_ItemCommand, (unless there is a way to call this event with a command on the button control.) I am attempting the SqlDataSource update by: Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click SqlDataSource1.Update() End Sub and: Protected Sub SqlDataSource1_Updating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceCommandEventArgs) Handles SqlDataSource1.Updating Dim totalcost As Single = 400 e.Command.Parameters("@TotalCost").Value = totalcost 'SqlDataSource1.UpdateParameters("TotalCost").DefaultValue = totalcost End Sub Neither the e.Command.Parameters("@TotalCost").Value = totalcost or the SqlDataSource1.UpdateParameters("TotalCost").DefaultValue = totalcost has any impact. Any help would be greatly appreciated....thank you
why don't you create a sql stored procedure, send the parameters and update the table which you want to be updated. It's really easy to update a field programatically. Check this link for more info regarding stored procedure and this link for playing with stored procedures in asp.net hope that can help, Laziale