0

I keep getting an exception when I try to fill the adapter and i can't figure out why. Here is my code. Thank you very much in advance for any information!

public partial class MainWindow : Window
{
    private OleDbConnection connection;
    private OleDbCommand command;
    private OleDbDataAdapter adapter;
    private DataSet dataset;

    public MainWindow()
    {
        InitializeComponent();

        connection = new OleDbConnection();
        command = new OleDbCommand();
        adapter = new OleDbDataAdapter();
        dataset = new DataSet();

        connection.ConnectionString =
            @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:/SoBeWFF.accdb;" +
            "Persist Security Info=False";

        command.Connection = connection;
        command.CommandText = "SELECT * FROM Dishes";

        adapter.SelectCommand = command;

        try
        {
            adapter.Fill(dataset, "Dishes");
        }
        catch (OleDbException)
        {
            MessageBox.Show("Error occured while connecting to database.");
           // Application.Exit();
        }
    }
}
2
  • Can you post what exception you are getting? Commented Feb 16, 2012 at 11:36
  • Without exception error, is hard to understand! Commented Feb 16, 2012 at 11:38

1 Answer 1

1

Try the following connection string. (Close the MS-Access/database file if it is opened)

connection.ConnectionString =@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\SoBeWFF.accdb";
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for answering my post! Unfortunately that did not help... I'm getting the following exception at adapter.fill(dataset, "Dishes"): 'The invocation of the constructor on type 'SoBeWFF.MainWindow' that matches the specified binding constraints threw an exception.' Line number '3' and line position '9'.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.