Solved

ADODB MS Access Statement

Posted on 2011-03-11
2
224 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

696 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