Results 1 to 8 of 8

Thread: [RESOLVED] RESOLVED (Can't save textbox data into sql database, Help!)

Threaded View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2009
    Posts
    115

    Resolved [RESOLVED] RESOLVED (Can't save textbox data into sql database, Help!)

    Hi

    I am currently puting together a data driven application just for fun and to get to know sql. The problem i am having is on my new customer form i can not get the data in my text boxes to save into my database table at runtime.

    I simply have 4 textboxes and a save button the code for my save button is as follows:
    Code:
    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
            Dim Connection As SqlConnection = MSDB.GetConnection
            Dim mySqlCommand As SqlCommand = New SqlCommand
            Connection.Open()
    
            mySqlCommand.Connection = Connection
            Try
                mySqlCommand.CommandText = "INSERT INTO customers (CustomerID, Customer, Contact, Email) VALUES ('@CustomerID', '@Customer', '@Contact', '@Email')"
    
                Dim InsertCommand As SqlCommand = New SqlCommand
                InsertCommand.Parameters.AddWithValue("@CustomerID", tbCustomerID.Text)
                InsertCommand.Parameters.AddWithValue("@Customer", tbCustomer.Text)
                InsertCommand.Parameters.AddWithValue("@Contact", tbContact.Text)
                InsertCommand.Parameters.AddWithValue("@Email", tbEmail.Text)
    
                mySqlCommand.ExecuteNonQuery()
                MessageBox.Show("New Customer Added To Your Database")
            Catch ex As Exception
                MessageBox.Show("Customer could not be added!" & ex.Message)
            Finally
                If Connection.State = ConnectionState.Open Then
                    Connection.Close()
                End If
            End Try
    
        End Sub
    All this does is bring up an error in runtime please can someone help me fix this so that when i press save the details in my text boxes are actually saved into my database table

    Thanks Roo
    Last edited by Roofuss; Apr 19th, 2009 at 08:00 AM. Reason: Resolved

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