I created a working Windows Forms project in C# that accesses an Access database of recipes. Using table adapters and the dataset I am able to query, update and insert new data into the database.
I created a new VS project, imported my database and started a new class. My problem is when I try to set up the table adapters I get errors, specifically with the .Fill() method. When I check the datasource.xsd I can see that the .get() and .Fill() methods were created but I can’t seem to access them like I did when I just dragged and dropped the binding source onto the WinForm previously.
I copied the code to programmatically create the table adapters from the MSDN website but I get the error on the line where I call ingredientTableAdapter.Fill(recipiesNewDataSet); method. Any one have a clue why? Here’s my code on this project so far:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MyRecipeDataBase
{
class QueryClass
{
recipiesNewDataSet recipiesNewDataSet = new recipiesNewDataSet();
recipiesNewDataSetTableAdapters.IngredientTableAdapter ingredientTableAdapter = new recipiesNewDataSetTableAdapters.IngredientTableAdapter();
ingredientTableAdapter.Fill(recipiesNewDataSet);
}
}
The answer was staring me in the face!
You’re putting code directly in the
classbody. It should be inside afunction. Inside the class constructor, for instance.