Problem with OleDbDataAdapter.Fill()

  • Thread starter Thread starter William Ryan
  • Start date Start date
W

William Ryan

The dataadapeter automatically Opens and Closes a
connection when you Fill/Update etc. Since you aren't
using any parameters in your query, the parameters in
question is most likely one in the connections string.
To test this, try using con.Open() somewhere before the
call to .fill and see if you get a clean open, I don't
think you will get one though. I suspect that your
problem is that the "\" character is an escape character
in C# and typically you'll need to either use the @
symbol before it or use double "\". So try using

string conString = "Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=" + "@" + openFileDialog1.FileName;

If this doesn't work, I'd guess it's a security problem..
Your database might need the userid and password and I
suspect that's probably the problem. Typically, I think
you need to pass four parameters to the OLEDB
connectionstring but I'm not totally positive (90% sure
though). If you get a clean open then I'm not sure what
your problem is based on that error message. If you
don't, try adding username /password and see if that
fixes it. If not, copy the mdb file locally on your
machine and hardcode the file path. See if that does it.

Here's a link you may find helpful. I'm pretty sure it's
one of those two problems.

Good Luck,

Bill

W.G. Ryan
(e-mail address removed)
www.knowdotnet.com
-----Original Message-----
Hi,
I'm totally new to ADO.NET and try to go through some basic steps. The code
below is from a simple project with a button that opens a OpenFileDialog and
lets me connect to a MSAccess database. Currently I always use the same
database which has a table 'kunden'.
All seems to work well until I call the data adapters Fill() method. The
exception thrown is unfortunately in german on my machine:
'Fuer mindestens einen erforderlichen Parameter wurde kein Wert angegeben'
what I would roughly translate to:
'For at least one required parameter no value was provided'

any ideas what is wrong?
thanks,
Nick

private void buttonOpen_Click(object sender, System.EventArgs e)
{
if(openFileDialog1.ShowDialog() == DialogResult.OK)
{
string conString
= "Provider=Microsoft.Jet.OLEDB.4.0; Data Source="
 
thanks Bill,
finally the error was simply a wrong SQL statement
(wrong tablename/fieldname combination), sorry about that!
Since the error message was very unclear to me I had to no
idea what is wrong. However, I learned a lot while searching
for the problem. When experimenting with Username and
Password I asked myself where do I find reference
information on building connection strings. Do you know
any good link?
Then I ran into a new problem with the correct tablename/
fieldname which is:
"SELECT Name FROM Names"
This works only when I put 'Names' into []. (I read other
posts where people had such problems). Do you know
of a list of reserved words for SQL statements?

thanks for the help,
Nick
 
Back
Top