Solved

Filling a dataset from an Access database using OLEDB.OLEDBConnection

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
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 …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

759 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

23 Experts available now in Live!

Get 1:1 Help Now