Whats wrong with this code for database insert?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • twsaustralia
    New Member
    • Oct 2006
    • 1

    Whats wrong with this code for database insert?

    Public Class Customerdetails
    Inherits System.Windows. Forms.Form

    Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click
    updatecustomerd atabase("Insert INTO Customer (FirstName), VALUES cstr(txtcustome rname.text)")

    End Sub
    Sub updatecustomerd atabase(ByVal sqlStr As String)
    Dim newcustomer As New DataTable
    Dim connStr As String = "Provider=Micro soft.Jet.OLEDB. 4.0;" & _
    "Data Source = maindatabase.md b"
    Dim dataAdaptor4 As New OleDb.OleDbData Adapter(sqlStr, connStr)
    dataAdaptor4.Fi ll(newcustomer)
    dataAdaptor4.Di spose()

    End Sub
    End Class
  • Metalzed
    New Member
    • Sep 2006
    • 27

    #2
    Originally posted by twsaustralia
    Code:
    Public Class Customerdetails
        Inherits System.Windows.Forms.Form
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            updatecustomerdatabase("Insert INTO Customer  (FirstName), VALUES cstr(txtcustomername.text)")
    
        End Sub
        Sub updatecustomerdatabase(ByVal sqlStr As String)
            Dim newcustomer As New DataTable
            Dim connStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                                    "Data Source = maindatabase.mdb"
            Dim dataAdaptor4 As New OleDb.OleDbDataAdapter(sqlStr, connStr)
            dataAdaptor4.Fill(newcustomer)
            dataAdaptor4.Dispose()
    
        End Sub
    End Class
    I am not sure
    But it could be this

    "Insert INTO Customer (FirstName), VALUES cstr(txtcustome rname.text)"

    is not a proper SQL query.
    is txtcustomername a textbox?

    then the row
    updatecustomerd atabase("Insert INTO Customer (FirstName), VALUES cstr(txtcustome rname.text)")

    should be change to
    updatecustomerd atabase("Insert INTO Customer (FirstName), VALUES '" + cstr(txtcustome rname.text) + "'")

    notice the '
    hope this was a help.

    Comment

    Working...