none
error syntax From clause vb RRS feed

  • Question

  • Defense_1.Items.Clear()
            'Try
            '    con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;" & "Data Source = C:\Users\BusinessOffice1Room\Documents\Waliur File\A Level\Computer Science\Coursework\Work In progression\State of War League Table.mdb"
            '    'con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;" & "Data Source = N:\Computer Science Coursework\Work In progression\State of War League Table.mdb"
            '    con.Open()
            '    da = New OleDb.OleDbDataAdapter(sqlv3, con)
            '    da.Fill(ds, "Counter")
            '    sqlv3 = "SELECT * From Counter WHERE Defences= " & "'" & Defense_1.Text & "'"
            '    da = New OleDb.OleDbDataAdapter(sqlv3, con)
            '    con.Close()
            '    con.Open()
            '    da.Fill(ds, "Counter")
            '    For i As Integer = 0 To ds.Tables("Counter").Rows.Count - 1
            '        Me.Defense_1.Items.Add(ds.Tables("Counter").Rows(i)(0))
            '    Next
            'Catch ex As Exception
            '    MsgBox("Error : " + ex.Message)
            'Finally
            '    con.Close()
            'End Try

    This is the following code. the part where it shows "SQLV3" is precisely where the error happens. Im open up to as many solutions possible.

    Saturday, March 4, 2017 4:13 PM

Answers

  • The keyword Counter is an Access reserved word. If you absolutely must use it then it must be enclosed in brackets (e.g. [Counter]).

    I would recommend renaming this table to something different.

    Also, I would recommend using Parameters for the SelectCommand of your OleDbDataAdapter.


    Paul ~~~~ Microsoft MVP (Visual Basic)


    Saturday, March 4, 2017 5:29 PM

All replies


  • Regards Les, Livingston, Scotland

    Saturday, March 4, 2017 4:33 PM
  • I see Ill enable that feature 
    Saturday, March 4, 2017 4:58 PM
  • The keyword Counter is an Access reserved word. If you absolutely must use it then it must be enclosed in brackets (e.g. [Counter]).

    I would recommend renaming this table to something different.

    Also, I would recommend using Parameters for the SelectCommand of your OleDbDataAdapter.


    Paul ~~~~ Microsoft MVP (Visual Basic)


    Saturday, March 4, 2017 5:29 PM
  • I tried changing the name it still says the same error. I changed the table name to shield. Am I missing something?
    Defense_1.Items.Clear()
            Try
                con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;" & "Data Source = C:\Users\BusinessOffice1Room\Documents\Waliur File\A Level\Computer Science\Coursework\Work In progression\State of War League Table.mdb"
                'con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;" & "Data Source = N:\Computer Science Coursework\Work In progression\State of War League Table.mdb"
                con.Open()
                da = New OleDb.OleDbDataAdapter(sqlv3, con)
                da.Fill(ds, "Counter")
                sqlv3 = "SELECT * From Shield WHERE Defences= " & "'" & Defense_1.Text & "'"
                da = New OleDb.OleDbDataAdapter(sqlv3, con)
                con.Close()
                con.Open()
                da.Fill(ds, "Shield")
                For i As Integer = 0 To ds.Tables("Shield").Rows.Count - 1
                    Me.Defense_1.Items.Add(ds.Tables("Shield").Rows(i)(0))
                Next
            Catch ex As Exception
                MsgBox("Error : " + ex.Message)
            Finally
                con.Close()
            End Try

    Saturday, March 4, 2017 11:33 PM
  • Have you tried using Parameters for your SelectCommand? I don't know what the value of Defense_1.Text is but that could also be causing the problem.

    Also, why do you close the connection and then re-open before calling Fill?


    Paul ~~~~ Microsoft MVP (Visual Basic)

    Sunday, March 5, 2017 4:48 AM
  • Defense_1 is the name for the combobox which displays the list of the items btw. Also I dont know much about that parameter for the selectcommand. Could you possibly give an example putting my code into context and If you want I can send a screenshot of the program
    Sunday, March 5, 2017 10:36 AM
  • Thank you everyone for helping me with my solution, it means the world to me when generous people like you want to help someone who struggles with programming and help them get better. I realise that the defense feature wasn't necessary because the turrets I put in such as grand cannon is an example of infrastructure so all the info from the table under counter I moved to my table referred with building names.

    Thank you again and keep helping the underdogs such as me ;)

    Sunday, March 5, 2017 1:09 PM