Inserting a Record Into SQL

Discussion in 'ASP .Net' started by Justin Musick, Oct 30, 2003.

  1. 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
    Justin Musick, Oct 30, 2003
    #1
    1. Advertising

  2. Justin Musick

    H Branyan Guest

    after opening the connection,

    insertWO.ExecuteNonQuery()


    --
    [[((hillarie))]]

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



    "Justin Musick" <> wrote in message
    news:3fa12b3e$0$71480$...
    > 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
    >
    >
    H Branyan, Oct 30, 2003
    #2
    1. Advertising

  3. You're the man, thanks much!

    jM

    "H Branyan" <> wrote in message
    news:bnrbt6$14ik4e$-berlin.de...
    > after opening the connection,
    >
    > insertWO.ExecuteNonQuery()
    >
    >
    > --
    > [[((hillarie))]]
    >
    > To reply by email, remove ".SPAMBLOCK" from email address
    >
    >
    >
    > "Justin Musick" <> wrote in message
    > news:3fa12b3e$0$71480$...
    > > 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
    > >
    > >

    >
    >
    Justin Musick, Oct 31, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew Banks

    Inserting dates into SQL Server DB

    Andrew Banks, Jan 5, 2004, in forum: ASP .Net
    Replies:
    11
    Views:
    618
    Andrew Banks
    Jan 7, 2004
  2. .Net Newbie
    Replies:
    0
    Views:
    300
    .Net Newbie
    Aug 24, 2004
  3. Chad Dittmer via .NET 247

    problems inserting into sql using SqlHelper.ExecuteScalar

    Chad Dittmer via .NET 247, Sep 15, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    2,512
    Hermit Dave
    Sep 15, 2004
  4. Replies:
    1
    Views:
    389
    sengsational
    Oct 13, 2007
  5. Meszaros, Stacy

    Inserting record into postgresql database

    Meszaros, Stacy, Mar 11, 2011, in forum: Python
    Replies:
    0
    Views:
    179
    Meszaros, Stacy
    Mar 11, 2011
Loading...

Share This Page