0

I upon button click i retrieve and place data onto a datagridview. However, after i change the "Location", the location and execute button click i receive an error. Below is the code i have and the error i receive.

Code:

private void button1_Click(object sender, EventArgs e)
     { UpdateDG(); }

private void UpdateDG()
    {                     
   Con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=F:\\DbFile\\MasterData.accdb");

        Con.Open();      
        DataTable dt = new DataTable();       
        OleDbDataAdapter da = new OleDbDataAdapter();           

        da = new OleDbDataAdapter("Select Inc1, Inc2 from MTable where Loc='" + Location+ "'", Con);

        da.Fill(dt);
        Dg.DataSource = dt;
        Dg.Columns[0].HeaderText = "IncTest1";
        Dg.Columns[1].HeaderText = "IncTest2";

        Con.Close();

Error:

The Microsoft Access database engine cannot find the input table or query 'MasterTable'.

hex c
  • 705
  • 2
  • 13
  • 22
  • IS your MTable the same as you mentioned as MasterTable? – khaled4vokalz Jan 16 '16 at 08:55
  • Start with removing the Location variable. Hard-code a known good Location value and see what happens. When you use string concatenation to build queries bad things can happen. – Crowcoder Jan 16 '16 at 13:06

0 Answers0