Solved

Filling a dataset from an Access database using OLEDB.OLEDBConnection

Posted on 2004-10-01
4
218 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
4 Comments
 
LVL 14

Accepted Solution

by:
ptakja earned 250 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Expando 4 47
Get String split 5 48
Receiving a string from a WebService Push 21 37
Close tabpage of custom control 9 23
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now