Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ADODB MS Access Statement

Posted on 2011-03-11
2
Medium Priority
?
226 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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

604 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