How to Make VB.NET Console Application with MS Access Databse 2007
Submitted by teody882012 on Sunday, August 4, 2013 - 22:23.
This is a VB.Net Console Application program using Access Database 2007. It is very helpful in learning VB.Net with Database Programming.
Instead of using Windows Forms, this program is using console application to insert record into MS Access database.
Please follow the steps below on how to create a console application from scratch.
1. Create the database file called "database1.mdb" by opening the MS Word file called "How to Create DB in 2007.doc" and follow the instruction.
2. Open Visual Studio Editor.
3. Click File >> New Project.
4. Select Visual Basic >> Console Application.
5. Click OK.
6. Paste the following code in module1.vb
- Imports System.Data.OleDb
- Module Module1
- Sub Main()
- Dim MyInput As String
- Call MainMenu()
- 'Main Menu
- Console.WriteLine("Press r or R to Return in Main:")
- Console.WriteLine("Press x or X to Exit Program:")
- MyInput = Console.ReadLine
- If MyInput = "r" Then
- Console.Clear()
- Call MainMenu()
- ElseIf MyInput = "x" Then
- End
- End If
- Console.Read()
- End Sub
- Sub MainMenu()
- 'We Declare a String
- Dim MyISBN As String
- Dim MyAuthor As String
- Dim MyTitle As String
- Dim Category As String
- Dim DatePublished As String
- 'We Print an Output
- Console.Write("Please Enter ISBN: ")
- MyISBN = Console.ReadLine
- Console.Clear()
- Console.Write("Please Enter Author Name: ")
- MyAuthor = Console.ReadLine
- Console.Clear()
- Console.Write("Please Enter Book Title: ")
- MyTitle = Console.ReadLine
- Console.Clear()
- Console.Write("Please Enter Book Category: ")
- Category = Console.ReadLine
- Console.Clear()
- Console.Write("Please Enter Book Dat Published: ")
- DatePublished = Console.ReadLine
- Console.Clear()
- 'We Create a 2 Space
- Console.WriteLine()
- Dim MyConnection As New OleDbConnection
- Dim MyCommand As New OleDbCommand
- Dim MySQL As String
- MySQL = "Insert Into books(isbn,author,title,category,datepublished) Values('" & MyISBN.ToString & "','" & MyAuthor.ToString & "','" & MyTitle.ToString & "','" & Category.ToString & "','" & DatePublished.ToString & "') "
- MyConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Database1.mdb")
- MyCommand = New OleDbCommand(MySQL, MyConnection)
- MyConnection.Open()
- MyCommand.ExecuteNonQuery()
- Console.WriteLine("Data save in the Database!!!")
- Console.WriteLine()
- End Sub
- End Module
Embed database1.mdb in the project.
1. Right click ConsoleApplication1 >> Click Add >> Click Existing Item. 2. Browse the database1.mdb >> Click Add. 3. Click Cancel if the Data Source Configuration Wizard appear on your screen. I hope it is very helpful. Teody BanaganAdd new comment
- 685 views