Have you changed any of the field names? I got this error when I had used Access to change a field name in my database. The old name was "DisbursementType". The new name was "ExpenseType". I used a query with the new field name to fill a dataset which worked fine.
string sqlQuery = "select * from Finance WHERE ExpenseType = 'MISC'";
System.Data.OleDb.OleDbCommand obiwan = new System.Data.OleDb.OleDbCommand();
obiwan.CommandText = sqlQuery;
this.financeTableAdapter.Adapter.SelectCommand.CommandText = sqlQuery;
this.financeTableAdapter.Fill(homeFinanceDataSet.Finance);
Using the same query string to open a record set failed.
string sqlQuery = "select * from Finance WHERE ExpenseType = 'MISC'";
string dbaseaddress = "";
ADODB.Recordset RS = new ADODB.Recordset();
if (openFileDialog1.ShowDialog()== DialogResult.OK)
{
dbaseaddress = openFileDialog1.FileName;
ADODB.Connection fc = new ADODB.Connection();
string str = "Provider=Microsoft.ACE.OLEDB.12.0;" +
"Data Source=" + dbaseaddress + ";" +
"Jet OLEDB:Database Password=" + "password" + ";";
fc.Open(str);
RS.Open(sqlQuery, fc, ADODB.CursorTypeEnum.adOpenStatic, &_
ADODB.LockTypeEnum.adLockOptimistic,0);
An exception is thrown at the last line: "System.Runtime.InteropServices.COMException: 'No value given for one or more required parameters.'"
When the original name for the field is used no exception is thrown.
string sqlQuery = "select * from Finance WHERE DisbursementType = 'MISC'";
string dbaseaddress = "";
ADODB.Recordset RS = new ADODB.Recordset();
if (openFileDialog1.ShowDialog()== DialogResult.OK)
{
dbaseaddress = openFileDialog1.FileName;
ADODB.Connection fc = new ADODB.Connection();
string str = "Provider=Microsoft.ACE.OLEDB.12.0;" +
"Data Source=" + dbaseaddress + ";" +
"Jet OLEDB:Database Password=" + "password" + ";";
fc.Open(str);
RS.Open(sqlQuery, fc, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic,0);
MessageBox.Show(string.Format("{0}",RS.RecordCount));