VB.NET – Database Connection
What we will learn today:
Creating a new database
Database connection using oledb
Retrieving data from database
Manipulating data in database from VB.NET application
Creating New Database and Table
Open your SQL Server Management Studio, and connect to your database engine {draw:frame}
After connecting, the screen will show you something like this {draw:frame}
We will create a new database, expand the ‘Databases’ folder, then right click on it, the choose ‘new database’ {draw:frame}
Type a new name for your database ‘forHCI’, and click ok (we will leave everything else by default)
Your new database should be created and shown in the object explorer.
{draw:frame}
Expand it and right click on the ‘tables’ folder and choose ’new table’. Type in three new column named ‘id_barang’, ‘nama_barang’, and ‘harga’, just like the screenshot below. {draw:frame}
Save your new table by clicking the save icon, name it ‘barang’. {draw:frame}
We want to fill the table for initial data to work with in the VB.NET application. Right click on the table ‘barang’ and choose ‘edit top 200 rows’, and type in some data. {draw:frame}
Alternatively you can insert data into the table from the query. You can open a new query window by clicking ‘new query’ button.
{draw:frame}
Then type in insert query in the query window
{draw:frame}
The tables are ready for our practice. Database Connection
We will use the previous project (last week, MDI form) or alternatively you can create a new project.
If you use the previous project, create a new menu item and a new form and name it ‘database’ then add some sub menu item ‘Retrieve’ and ‘Insert Update Delete’
{draw:frame}
Create two new forms ‘frmretrieve’ and ‘frminsupdel’ and link it to the new menu item...
No comments