Solved

ADODB MS Access Statement

Posted on 2011-03-11
2
223 Views
Last Modified: 2012-05-11
I have written a vb.net app that executes a SQL Statement on a MSACCESS database.

It uses the attatched SQL code to query an access database.

if there is a number in the LoggedOn fields in the ACCESS database then it works fine

however if there is no number i get the error "Unspecified Error" on the "rs2.Open(sqlstr2, Local1stCnnString, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)" line of the code.

Can anybody see why?
Dim rs2 As New ADODB.Recordset
Dim sqlstr2 As String

sqlstr2 = "SELECT UserName FROM LocalUser WHERE LoggedOn <> 0"

rs2.Open(sqlstr2, Local1stCnnString, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)

Open in new window

0
Comment
Question by:ict-torquilclark
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 35108963
you rather shall do it:
Dim cnn as ADODB.Connection
Dim rs2 As ADODB.Recordset
Dim sqlstr2 As String

set cnn = new ADODB.Connection
cnn.open Local1stCnnString

set rs2 = new ADODB.Recordset
set rs2.ActiveCOnnection = cnn
rs2.CursorType = ADODB.CursorTypeEnum.adOpenStatic
rs2.LockType = ADODB.LockTypeEnum.adLockOptimistic

sqlstr2 = "SELECT UserName FROM LocalUser WHERE LoggedOn <> 0"

rs2.Open sqlstr2

Open in new window

0
 
LVL 53

Expert Comment

by:Dhaest
ID: 35109011
One big remark: why are you still using adodb instead of ado.net ?
Dim connetionString As String
        Dim cnn As OleDbConnection
        Dim cmd As OleDbCommand
        Dim sql As String
        Dim reader As OleDbDataReader

        connetionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Your mdb filename;"
        sql = "SELECT UserName FROM LocalUser WHERE LoggedOn <> 0"

        cnn = New OleDbConnection(connetionString)
        Try
            cnn.Open()
            cmd = New OleDbCommand(sql, cnn)
            reader = cmd.ExecuteReader()
            While reader.Read()
                MsgBox(reader.Item(0))
            End While
            reader.Close()
            cmd.Dispose()
            cnn.Close()
        Catch ex As Exception
            MsgBox("Can not open connection ! ")
        End Try

Open in new window

0

Featured Post

Independent Software Vendors: 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

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…
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

733 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