Inserting a Record Into SQL

J

Justin Musick

I'm having some trouble inserting a record into a SQL database from a simple
form. When the "txtName" text box is filled and the button is clicked, I
get no error but no record is added to the database.

My code is:

Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSubmit.Click

Dim insertCmd As String = "INSERT INTO tblCustomer (cusName) VALUES
(@cusName)"

Dim insertWO As SqlCommand

daWO.Fill(DsWO1)

insertWO = New SqlCommand(insertCmd, cnnWO)

insertWO.Parameters.Add(New SqlParameter("@cusName", SqlDbType.NVarChar,
50))

insertWO.Parameters("@cusName").Value = txtName.Text

insertWO.Connection.Open()

'Sends user to success page once data successfully is entered

Response.Redirect("wosuccess.htm")

End Sub
 
J

Justin Musick

You're the man, thanks much!

jM

H Branyan said:
after opening the connection,

insertWO.ExecuteNonQuery()


--
[[((hillarie))]]

To reply by email, remove ".SPAMBLOCK" from email address



Justin Musick said:
I'm having some trouble inserting a record into a SQL database from a simple
form. When the "txtName" text box is filled and the button is clicked, I
get no error but no record is added to the database.

My code is:

Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSubmit.Click

Dim insertCmd As String = "INSERT INTO tblCustomer (cusName) VALUES
(@cusName)"

Dim insertWO As SqlCommand

daWO.Fill(DsWO1)

insertWO = New SqlCommand(insertCmd, cnnWO)

insertWO.Parameters.Add(New SqlParameter("@cusName", SqlDbType.NVarChar,
50))

insertWO.Parameters("@cusName").Value = txtName.Text

insertWO.Connection.Open()

'Sends user to success page once data successfully is entered

Response.Redirect("wosuccess.htm")

End Sub
 

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,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top