Click here to Skip to main content
13,453,957 members (44,240 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hello, I'm trying to retreive values from a database using visual studio 2010/c# and access 2010, but the set doesn't seem to be filling, the messagebox testing it doesn't even show up. Here is the code I have.

string cmd = "asd";
string myconstring = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=F:\Users\Jacob\Desktop\Database11.accdb";
OleDbConnection con = new OleDbConnection(myconstring);
OleDbCommand com = new OleDbCommand(cmd, con);
OleDbDataAdapter adp = new OleDbDataAdapter(com);
DataSet set = new DataSet();
    adp.Fill(set);MessageBox.Show("Did it work?");
    set = new DataSet();

I don't know why the message box isn't showing up right after, and because neither of the test message boxes are loading, I can't tell for sure if the data was even retrieved. Could anyone help?
Posted 2-Apr-13 6:05am
richcb 2-Apr-13 12:12pm
Well, "asd" is not a command to retrieve data. Are you using something other than that?
YdoUaskbeta 2-Apr-13 12:32pm
Ah, Welp, I'm dumb. After I ran it with a Select * from table1 (the only table, and it has 2 values. I was able to get the second message box, but not the last one. (Table one has two fields, ID and Field1. ID is 1 or 2 and Field1 is Test and Test num respectively)
richcb 2-Apr-13 12:34pm
Remove the "set = new DataSet();" before you show the last message. It is basically giving "set" a blank value when you do that.
ThePhantomUpvoter 2-Apr-13 12:50pm
Wow what a familiar question. I answered this exact same question with this exact same code just yesterday.
YdoUaskbeta 2-Apr-13 14:29pm
Thank you very much Pheonyx. And Phantom, sorry, I had to re-ask because next to edit it notified me that the question had been deleted.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

set = new DataSet();

That is because you are clearing the dataset by re-initialising it.

Why do you do this?!

set = new DataSet();
after you have done the "Did it work?" message box.
ThePhantomUpvoter 2-Apr-13 12:53pm
Offset the undeserved 1 vote. This is the correct answer. Also "asd" is not a select command. The messagebox is most likely not showing up due to an uncaught exception though.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01-2016 | 2.8.180321.1 | Last Updated 2 Apr 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100