Results 1 to 2 of 2

Thread: Helping Inserting Into Sql Database

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2002
    Posts
    68

    Unhappy Helping Inserting Into Sql Database

    I have a form that has three text boxes and one button . The user will fill in the three text boxes and then hit the button the Add the new info into the database. Here is the layout of the database.

    pk_Account_Id_Number <-AutoNumber
    char_Account_name <-User Will Supply
    date_Account_Open_Date <-User Will Supply
    int_Account_Balance <-User Will Supply

    I cannot figure out how to get the info from the textbox and into the database using code only.

    Thanks

  2. #2
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Your statement will be something like this:
    Code:
    "INSERT INTO YourTableName
    (char_Account_name, date_Account_Open_Date, int_Account_Balance)
    VALUES
    ('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "')"
    Use it like so:
    Code:
    Dim conn As SQLConnection = new SQLConnection("Yourconnectionstring")
    Dim command As SQLCommand = new SQLCommand("INSERT INTO YourTableName
    (char_Account_name, date_Account_Open_Date, int_Account_Balance)
    VALUES
    ('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "')", conn)
    command.Connection = conn
    conn.Open()
    command.ExecuteNonQuery()
    conn.Close()
    All that is done from memory, I didn't verify it, but it will be close. You also have to verify that all your text in your text boxes are the right type and format.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width