Solved

Filling a dataset from an Access database using OLEDB.OLEDBConnection

Posted on 2004-10-01
4
227 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

772 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