嗨,我正在尝试从 Ms Access 数据库中检索数据VC++
。由于我是新手VC++
,请帮助我。
这是我到目前为止编写的代码。
System::Data::DataSet^ ds=gcnew System::Data::DataSet();
OleDbConnection ^ con=gcnew OleDbConnection("Provider= Microsoft.ACE.OLEDB.12.0;Data source=dbmc.accdb; Persist Security Info=True");
OleDbCommand^ com =gcnew OleDbCommand();
OleDbDataReader^ myReader;
com->CommandText ="SELECT name FROM Table1";
com->Connection = con;
con->Open();
try
{
myReader=com->ExecuteReader();
while(myReader->Read())
{
String^ vName = myReader->GetString('name');
comboBox1->Items->Add(vName);
myReader->Close();
}
}
catch(Exception^ex)
{
MessageBox::Show(ex->Message);
}
当我运行这个程序时,我得到一个错误"Index Out of Bound"
。