Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Filling a dataset from an Access database using OLEDB.OLEDBConnection

Posted on 2004-10-01
4
Medium Priority
?
252 Views
Last Modified: 2010-04-23
I am attempting to fill a table "Employee" in dataset "dsHold" from a access database. When the code is run the following error is received "No value given for one or more required parameters. Microsoft JET Database Engine". Any help in understanding what the parameter is that is missing would be greatly appreciated.

Code: VB.Net (2003)
Try 'try is the beginning of the error handler
            'define the connection string to the local Access database
            conn2 = New System.Data.OleDb.OleDbConnection
            conn2.ConnectionString = ("Provider=Microsoft.Jet.OLEDB.4.0;Data source=C:\IT\Applications\DOA Application\Data\Tables.mdb")

           'open the connection to the Access database
            conn2.Open()
           
            'run a query against the database (table tblEmployee) attempting to match what was typed into the username box to the user name in the database table
            daEmployee2 = New OleDb.OleDbDataAdapter("SELECT * FROM tblEmployee WHERE UserName = " & CStr(Username), conn2)

            'now fill the data set "dsHold" table Employee with the record from the query above
  failure point===>          daEmployee2.Fill(dsHold, "Employee")
           
            'set the data adapter to nothing
            daEmployee2 = Nothing
           
            'close the connection to the Access database
            conn2.Close()

Catch eException As Exception
            If conn2.State = ConnectionState.Open Then
                conn2.Close()
            End If
            MsgBox("Error: " & eException.Message & " " & eException.Source)
        End Try

Thanks, MT
0
Comment
Question by:MajikTara
[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
4 Comments
 
LVL 14

Accepted Solution

by:
ptakja earned 1000 total points
ID: 12204577
I think the problem is related to your query:

daEmployee2 = New OleDb.OleDbDataAdapter("SELECT * FROM tblEmployee WHERE UserName = " & CStr(Username), conn2)

String parameters must be enclosed in single quotes.  Try this instead:

daEmployee2 = New OleDb.OleDbDataAdapter("SELECT * FROM tblEmployee WHERE UserName = '" & CStr(Username) & "'", conn2)

So for example, if my username was "Jeff", the query would like like this:

SELECT * FROM tblEmployee WHERE UserName = 'Jeff'
0
 

Expert Comment

by:Blitzman
ID: 12204714
0
 
LVL 1

Expert Comment

by:maykut
ID: 12222722
why not just add all your tables into one listbox and when you run your program you can select your table employee or any other table using the same code, which then displays it in the Datagrid. If you need help with this I can send you the code.
0
 

Author Comment

by:MajikTara
ID: 12260050
ptakja -

Thank you for seeing the error. As soon as you pointed out what I was doing wrong I kicked my self, I've had this same error before.

Thanks again,
MajikTara
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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
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

688 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