5 Replies - 4459 Views - Last Post: 24 September 2012 - 11:07 PM Rate Topic: -----

#1 ruzel  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 23-September 12

save the data i entered in textboxes into ms access using vb10

Posted 23 September 2012 - 09:17 PM

what is the possible problem of my code ? Im a creating a metric conversion system that will save the data entered in textbox into ms access, together with the converted value and its unit, the error was "syntax error in Insert into statement".
ty

      Dim dbInsert As New OleDb.OleDbCommand
        Dim dbConnect As New OleDb.OleDbConnection
        Dim Line As String = Environment.NewLine

            dbConnect.ConnectionString = "PROVIDER=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath & "\Database1.accdb"


            dbConnect.Open()
            MsgBox("Database is now open")

        dbInsert.CommandText = "Insert into convert (Num,From,To,Con_v) values('" & TextBox1.Text & "', '" & ComboBox1.Text & "', '" & ComboBox2.Text & "', '" & TextBox2.Text & "' )")
            dbInsert.CommandType = CommandType.Text
            dbInsert.Connection = dbConnect

        Try
        dbInsert.ExecuteNonQuery()
            MessageBox.Show("Access created Succesfully for ")
        Catch ex As Exception
            MessageBox.Show(ex.Message)

            dbConnect.Close()
            MsgBox("database is now close")

        End Try


    End Sub

This post has been edited by AdamSpeight2008: 24 September 2012 - 06:18 PM
Reason for edit:: WHAT IS IT ABOUT THE CODE TAG / BUTTON THAT MAKES IT SO HARD TO USE?


Is This A Good Question/Topic? 0
  • +

Replies To: save the data i entered in textboxes into ms access using vb10

#2 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1062
  • View blog
  • Posts: 4,143
  • Joined: 02-July 08

Re: save the data i entered in textboxes into ms access using vb10

Posted 23 September 2012 - 09:53 PM

Your using to many keywords for your table name and fields. Convert, From and To to be specific. Rename them and try again.
Was This Post Helpful? 1
  • +
  • -

#3 ruzel  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 23-September 12

Re: save the data i entered in textboxes into ms access using vb10

Posted 23 September 2012 - 10:14 PM

View Post_HAWK_, on 23 September 2012 - 09:53 PM, said:

Your using to many keywords for your table name and fields. Convert, From and To to be specific. Rename them and try again.

I already renamed the field , but the error is the same
Was This Post Helpful? 0
  • +
  • -

#4 jgferguson  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 31
  • Joined: 11-July 12

Re: save the data i entered in textboxes into ms access using vb10

Posted 24 September 2012 - 02:20 PM

Hi,

Each of the values in your sql statement is surrounded by a single speech mark meaning that MS Access will think that the value that is coming to it is text. If it is lookikng for text then all will be well but if it is looking for a number and it gets text MS Access will throw a data mismatch error which could be part of the problem - is field 'Num' looking for a number and what happens when it receives a text string?

Try putting a breakpoint in your code before the ExecuteNonQuery statement and capture the Commandtext in the Immediate window. At this point I copy it and paste it into a blank query in Access in the sql page and run the query again. Access might then give you a better idea of what the problem is.

Hope this helps.
Jerry.
Was This Post Helpful? 0
  • +
  • -

#5 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1606
  • View blog
  • Posts: 5,163
  • Joined: 25-September 09

Re: save the data i entered in textboxes into ms access using vb10

Posted 24 September 2012 - 02:58 PM

From is definately a keyword and will cause a Syntax error, either wrap it with [] or rename it
Insert into convert (Num,[From],To,Con_v) values...

Also, you have an extra parenthesis on that line but that should be apparent prior to ever running any of the code.

This post has been edited by CharlieMay: 24 September 2012 - 02:59 PM

Was This Post Helpful? 0
  • +
  • -

#6 ruzel  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 23-September 12

Re: save the data i entered in textboxes into ms access using vb10

Posted 24 September 2012 - 11:07 PM

View PostCharlieMay, on 24 September 2012 - 02:58 PM, said:

From is definately a keyword and will cause a Syntax error, either wrap it with [] or rename it
Insert into convert (Num,[From],To,Con_v) values...

Also, you have an extra parenthesis on that line but that should be apparent prior to ever running any of the code.


thanks for the response.. its working now.. :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1