processing aspx Web Form to a SQL 2000 DB

G

Guest

Hopefully I've got the right discussion group

I'm building using a web app using VS.NET 2002 / SQL 2000

The following should process the details from an online form to a SQL db but when the Submit is pressed, the form looks like it actions, but NOTHING is added to the DB! Am I missing an update statement ?
....I thought the following statement which is in the code below added the details to the DB: " DataSetClientReg1.ClientDetails.Rows.Add(RowNew) " would add the new row in the DB

( dataSetClientReg1 is set to the connection string in the code, which I think is correct.

Code

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Clic

'standard dim for adding the form dat
Dim RowNew As DataSetClientReg.ClientDetailsRow = DataSetClientReg1.ClientDetails.NewRo

'additional Dim to get the last entry in the D
Dim intID As Intege
Dim cmdNewRef As New SqlCommand("SELECT MAX(ClientRef) FROM ClientDetails", SqlConnection1

'get MAX value from ClientRe
SqlConnection1.Open(
intID = CInt(cmdNewRef.ExecuteScalar()
intID = intID +

' Adding the data for the form her
RowNew.ClientRef = intI

'Adding the normal form stuf
RowNew.ClientType = "GP
RowNew.ContactTitle = PracticeName.Tex
RowNew.Add1 = Add1.Tex
RowNew.Add2 = Add2.Tex
RowNew.Add3 = Add3.Tex
RowNew.Add4 = Add4.Tex
RowNew.PostCode = PostCode.Tex
RowNew.GPpracticeSize = PracticeSize.Tex
RowNew.GPcompSystem = CompSystem.SelectedInde
RowNew.ContactTitle = Title.SelectedInde
RowNew.ContactFirstName = FirstName.Tex
RowNew.ContactLastName = Surname.Tex
RowNew.Tel = Tel.Tex
RowNew.Fax = Fax.Tex
RowNew.Email = Email.Tex
RowNew.CameAwareofID = AwareofID.SelectedInde
RowNew.CameAwareofIDother = AwareofIDOther.Tex
RowNew.AdditionalInfo = AdditionalInfo.Tex

'Adding the date and make account activ
RowNew.DateRegistered = Date.No
RowNew.Active = "y

'try to commit the update to the D
DataSetClientReg1.ClientDetails.Rows.Add(RowNew

SqlConnection1.Close(

'once committed, goto another pag
Server.Transfer("../LogIn/ClientsLogIn.aspx"
End Sub
 
P

Patrick Leong

Based on the code you posted, you have only added a row into the DataSet,
which is "disconnected" from the Database. In order to post the update, you
need to use a DataAdapter (it can be the DA used for filling out the
DataSet) to post the update back to the DB.

Remember, DataSet is disconnected by nature, i.e. it's only a cache of the
retrieved data, whatever you change in the DataSet, it will not be
automatically submit back to the database until you explicitly update it,
using SQL statement or DataAdapter.

Hope it helps. Greetings.
 
P

Patrick Leong

It depends if you're using an DataAdapter to fill in the DataSet. Suppose
you have a SqlDataAdapter (let's say the variable name is "da") in your
class' designer (added by drag-and-drop from toolbox), just configure it to
also generate INSERT/DELETE/UPDATE statements, and use

da.Update(DataSetClientReg);

to update the whole DataSet back to the db. As long as the
INSERT/DELETE/UPDATE statements are correct, this is the easiest way.

If you create your own SqlDataAdapter, though, you've got some more stuff to
do. You got to new a SqlCommand object (with the SqlConnection object, of
course), add parameters for every column, and assign this SqlCommand to the
UpdateCommand property of the SqlDataAdapter. For this I'm not very
experienced with it, please refer to MSDN for how to write SqlCommand
objects for Update.

Hope it helps.
 

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