Using Visual Basic (and .NET 4) in Visual Studio 2010, I would like to read from an Access 2007 .accdb Database.
I used the build in Wizard to connect to the database (without importing it into the project), that is: “Add New Data Source” > “Database” > …
A ConnectivityString is then automatically generated.
Many articles on the net speak about how to connect to a database using connections strings like Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myAccess2007file.accdb;Persist Security Info=False;
But I have already several of such commands (automatically generated) in my App.config file. For example:
<connectionStrings>
<add name="Wolf_Calc.My.MySettings.wolf_calcConnectionString"
connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\wolf-calc.accdb"
providerName="System.Data.OleDb" />
Can I then just start writing queries in my code and just do something like
value = table1.SearchCriterion("x").SearchRange("y")?
When using the Wizard to add a Data Source, the connection strings are automatically created. But there are still some more steps to do in order to be able to use properly the Database.
Load the data into a table you can use. For example, let’s say I have a database named StarTrek containing a table Enterprise. The following line loads the data into the Enterprise table:
Create a scalar query. It will find a single value into your table. In the Data Designer, add a query to the Enterprise table (right click on the TableAdapter zone).
If the desired result is the age (column “Age”) of Mister Spock (column “Name”), the query will be:
The search can now take place. Let’s say you named the query ScalarQueryAge. The following displays the age of Mister Spock into a label.