ASP update to database, need sample or tutorial

L

Lloyd Sheen

In preparation for an app that will be a simple ASP.NET page with about 40
text boxes I need sample to do the following:

1. Select the current data (done)
2. Bind to the textboxes (done)
3. When user clicks the update button the page will update the data in the
database.

Existing code:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
Me.SqlConnection1.Open()
Me.SqlDataAdapter1.Fill(Me.TerrDataSet)
Me.DataBind()
Me.SqlConnection1.Close()
End If
End Sub

The above works and shows the value of the fields in the text boxes.


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim picnt As Integer
Me.SqlConnection1.Open()
Try
picnt = Me.SqlDataAdapter1.Update(Me.TerrDataSet)

Catch ex As Exception
Dim s As String = ex.Message
End Try
Me.SqlConnection1.Close()
End Sub

This code shows a count of 0 for the Update???
 
P

Prateek

Try filling the DataSet again before updating OR
store the dataset in a session variable and retrieve before updating.

-Prateek

In preparation for an app that will be a simple ASP.NET page with about 40
text boxes I need sample to do the following:

1. Select the current data (done)
2. Bind to the textboxes (done)
3. When user clicks the update button the page will update the data in the
database.

Existing code:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
Me.SqlConnection1.Open()
Me.SqlDataAdapter1.Fill(Me.TerrDataSet)
Me.DataBind()
Me.SqlConnection1.Close()
End If
End Sub

The above works and shows the value of the fields in the text boxes.


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim picnt As Integer
Me.SqlConnection1.Open()
Try
picnt = Me.SqlDataAdapter1.Update(Me.TerrDataSet)

Catch ex As Exception
Dim s As String = ex.Message
End Try
Me.SqlConnection1.Close()
End Sub

This code shows a count of 0 for the Update???
 
L

Lloyd Sheen

Ok, now how do the values in the text boxes get into the update statement.
Is this automatic??
If I fill the dataset again will it not have the initial values from the
select instead of the values from the textboxes?

Lloyd
 

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

Top