数据集未填写c#以访问2010数据库 [英] Dataset not filling in c# to access 2010 database
问题描述
您好,我正在尝试使用visual studio 2010 / c#和2010访问来修复数据库中的值,但该集似乎没有填充,测试它的消息框甚至都没有显示出来。这是我的代码。
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.
MessageBox.Show("Hello");
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);
con.Open();
DataSet set = new DataSet();
adp.Fill(set);MessageBox.Show("Did it work?");
set = new DataSet();
MessageBox.Show(Convert.ToString(set.Tables[0].Rows[0][0]));
我不知道为什么消息框没有立即出现,因为没有测试消息框正在加载,我无法确定数据是否被检索。任何人都可以帮忙吗?
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?
推荐答案
set = new DataSet();
MessageBox.Show(Convert.ToString(set.Tables[0].Rows[0][0]));
那是因为你通过重新初始化来清理数据集。
为什么这样做?!
完成它有效吗?后删除
That is because you are clearing the dataset by re-initialising it.
Why do you do this?!
Remove
set = new DataSet();
消息框。
这篇关于数据集未填写c#以访问2010数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!