Bad INSERT INTO statement

Joined
Mar 13, 2006
Messages
12
Programming Experience
Beginner
There's an error in my code, saying something about some INSERT INTO statement. Here's my code, give me whatever you can find out

VB.NET:
    Public Sub create_acc()
        Try
            Dim inc As Integer = 0
            Dim maxrows As Integer
            Dim con As New OleDb.OleDbConnection
            Dim dataset As New DataSet
            Dim newrow As DataRow
            If locale <> String.Empty Then
                con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = " & locale
                con.Open()
                Dim sql As String = "SELECT * FROM accounts"
                Dim adapter As OleDb.OleDbDataAdapter
                adapter = New OleDb.OleDbDataAdapter(sql, con)
                adapter.Fill(dataset, "DB")
                con.Close()
                Dim builder As New OleDb.OleDbCommandBuilder(adapter)
                newrow = dataset.Tables("DB").NewRow()
                Dim username As String = wizard.username
                Dim password As String = wizard.password
                newrow.Item(0) = username
                newrow.Item(1) = password
                newrow.Item(2) = 1
                dataset.Tables("DB").Rows.Add(newrow)
                adapter.Update(dataset, "DB")
                dbtry = 1
            Else
                MessageBox.Show("Please connect to the database first", "DB Error", 0, 16)
            End If
        Catch ex As OleDb.OleDbException
            MessageBox.Show(ex.Message, "Error", 0, 16)
            dbtry = 0
        Finally
            If dbtry = 1 Then
                wizard.bool = 1
                MessageBox.Show("Account created!", "DB", 0, 64)
            Else
                MessageBox.Show("Account creation failed...", "DB Error", 0, 16)
            End If
            dbtry = 0
        End Try
    End Sub

locale = The location of the connection address, stored elsewhere.


Sorry there's not much help I can give you.
 
I only had a chance to glance briefly but it looks like the problem with your INSERT INTO statement is that you haven't got one. Check out Sequel on the internet. There will be loads of info about using structured query language.
 
No, he is creating one, using the CommandBuilder class..... but the problem is that things like Password and USerName tend to be reserved keywords.....
Two ways to fix it:
1) Change the field names in the table
2) Manualy create the Insert statement yourself and put square brackets around the fields names [password] and [username]

-tg
 
Back
Top