Solved

Filling a dataset from an Access database using OLEDB.OLEDBConnection

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

821 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