Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

VB.net exception error

Posted on 2005-04-26
6
Medium Priority
?
518 Views
Last Modified: 2008-01-09
Hello!

I am creating a form with a database connection to MS Access and I keep getting this error message :

"Syntax error in query. Incomplete query clause"

Here is my code :

Try
            Dim f3DbConn As OleDb.OleDbConnection
            Dim f3DbCommand As OleDb.OleDbDataAdapter
            Dim DSf3 As New DataSet
            Dim f3sql As String
            f3DbConn = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & _
            "Data Source= Printer_DB.mdb")
            f3DbConn.Open()
            f3sql = "SELECT * FROM '" & CBF3Device.SelectedText & "'"
            f3DbCommand = New OleDb.OleDbDataAdapter(f3sql, f3DbConn)
            f3DbCommand.Fill(DSf3, "f3TableFill")
            f3DbConn.Close()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

What am I doing wrong?

Thanks in advance
0
Comment
Question by:abennett10
  • 3
  • 3
6 Comments
 
LVL 9

Expert Comment

by:Lacutah
ID: 13870617
Remove the quotes from your select command:
     For your SQL, Instead of:
            Select * from 'tablename'
     Use:
            Select * from tablename
     Or (for access):
           Select * from [tablename]
So your code could read:
       f3sql = "SELECT * FROM " & CBF3Device.SelectedText
0
 

Author Comment

by:abennett10
ID: 13870660
Now I receive Syntax error in FROM clause:

Try
            Dim f3DbConn As OleDb.OleDbConnection
            Dim f3DbCommand As OleDb.OleDbDataAdapter
            Dim DSf3 As New DataSet
            Dim f3sql As String
            f3DbConn = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & _
            "Data Source= Printer_DB.mdb")
            f3DbConn.Open()
            f3sql = "SELECT * FROM  " & CBF3Device.SelectedText
            f3DbCommand = New OleDb.OleDbDataAdapter(f3sql, f3DbConn)
            f3DbCommand.Fill(DSf3, "f3TableFill")
            f3DbConn.Close()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
0
 
LVL 9

Expert Comment

by:Lacutah
ID: 13870690
Is the tablename valid?  Does it have spaces, or is it a JET reserved word?  That is when you want to use the brackets ([]) around the table name.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:abennett10
ID: 13870717
The table name should pull what ever is the Text value from the Combobox CBF3Device is the Combobox.
0
 
LVL 9

Accepted Solution

by:
Lacutah earned 2000 total points
ID: 13870750
Oh, it's a Combobox.

Instead of using .SelectedText (misleading)
     f3sql = "SELECT * FROM  " & CBF3Device.SelectedText
Use SelectedItem:
     f3sql = "SELECT * FROM [" & CBF3Device.SelectedItem.tostring & "]"
0
 

Author Comment

by:abennett10
ID: 13870814
That worked!!!!

Thanks alot! that was great
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question