0

When i type

"dbProvider = "provider=microsoft.ace.oledb.12.0;"
        dbSource = "data source = d:/data1.accdb"
        con.ConnectionString = dbProvider & dbSource
        con.Open()
        sql = "select * from table 1"
        da = New OleDb.OleDbDataAdapter(sql, con)
        MsgBox("database is now open")
        da.Fill(ds, "ohr id/phr id")
        con.Close()
        MsgBox("database is now closed")"

However when i type the following code with a change in the sql query. It shows OLEDB Exception occurs.

"dbProvider = "provider=microsoft.ace.oledb.12.0;"
        dbSource = "data source = d:/data1.accdb"
        con.ConnectionString = dbProvider & dbSource
        con.Open()
        sql = "select column 1 from table 1"
        da = New OleDb.OleDbDataAdapter(sql, con)
        MsgBox("database is now open")
        da.Fill(ds, "ohr id/phr id")
        con.Close()
        MsgBox("database is now closed")"

Please tell me what is going wrong?. Thanks in advance P.S.:the code waroks fine till MsgBox("database is now open")...the problem appears only in da.Fill(ds,"...")

  • 1
    If your tables or columns contain spaces then enclose their names in square brackets – Steve Nov 21 '13 at 14:00
  • 2
    Two comments on your question in its current form: **(1)** As @Steve notes, it *sounds like* your table and/or column names have spaces in them and you need to enclose them in square brackets: `[column 1]`. **(2)** Your question in its current form is clearly wrong. `select * from table 1` *cannot* work. It will fail with "Syntax error in FROM clause." `select * from [table] 1` will work *if* the database contains a table named [table]. You have apparently obfuscated your table and column names to the point where we can't really help you because we don't know what you are *actually doing*. – Gord Thompson Nov 21 '13 at 14:54
  • @GordThompson..Thanks for the correction...i got the error it was the square brackets...i used table 1 to avoid givng the actual databse name.. :) – Sultan Shaik Nov 22 '13 at 10:18

0 Answers0