Inserting a Record Into SQL

  • Thread starter Thread starter Justin Musick
  • Start date Start date
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
 
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
 
Back
Top