The first thing you will need to do is create a access database, lets call it
student.mdb.
In the database, you will have a table called
students with 7 fields.
student.mdb
student_id - (numeric, auto-number)
last_name - (text, 20)
first_name - (text, 20)
age - (numeric)
city - (text, 20)
state - (text, 2)
zip - (text, 10)
Lets say you input some data:
the
student_id field must be a primary-key field and auto-numbered.
At least one field in each table should be auto-numbered to uniquely identify the record.
If you do not do this, then you will have problems inserting, updating and deleting records in
VB.net.
You can also use a unique text field instead of an ID field but keep in mind each record
must have a unique value.
let say the database is on the root of you hard drive
C:\student.mdb.
Now create a new VB.NET project and add a button and a datagrid (see image):
Double-Click the button and add the following code to button:
Here is the code, you can simply cut and paste:
Now, once we are done, you can compile the application and run it, the output should look like this:
This example shows the data from the database and the code needed to connect the 2.
If you are using a SQL server, you will use:
SqlClient.SqlDataAdapter("", "")
instead of
OleDb.OleDbDataAdapter. Each database has its own adapter.
You can also use
Odbc.OdbcDataAdapter to connect from any database via ODBC.
Also remember, each database will have its own connect string. More information about connection strings can be
found here.
Just make sure each table as a unique ID and you should be good to go!