How to connect Access Database in MS VB.net 2013


Here is how you can connect and build a Access data base application in Visual Basic.Net. First we need a connection string and Data Adapter or a command object for executing SQL statements. We can execute SQL commands using either the Adapter or the OLEDB command object.

In ADO.net there are plenty of class which make connecting database smooth as silk. Lets do it

Create connection string  

    Public Company As OleDb.OleDbConnection

Now we can configure the connection string.
        Company = New OleDb.OleDbConnection
        Company.ConnectionString = “Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\.Net Project\Accounting Pack\AccountingPack.accdb”

We are ready to interact with any table in AccountingPack database

Interacting with table

As far as we got everything is right and need to add, retrieve,update and delete rows to the table in the data base. The CURD operation can be made possible with a command object.

 Company.open()
  Dim cmd As OleDbCommand = New OleDbCommand(“select * from product_registration”, Company)

The first argument is the SQL query statement which fetch all columns from the table and the second is the connection string. Before executing this we also need to open the concoction.
To print the rows we need another object called  OleDbDataReader which help us to fetch row from command object and it works with following code

 Dim reader As OleDbDataReader = _
        cmd.ExecuteReader(CommandBehavior.CloseConnection)
        Do While reader.Read
            Console.WriteLine(reader.GetString(0))
        Loop
        reader.Close()
        Company.Close()

Insert statement

All other SQL statements can be made possible with the OleDbCommand object. 

Company.Open()
        Dim s As String = TextBox1.Text
        Dim cmd1 As OleDbCommand = New OleDbCommand(“insert into  product_registration (pruduct_name) values(‘” & s & “‘)”, Company)
        cmd1.ExecuteScalar()
        Company.Close()
Saving record is possible with ExecuteScalar method and it will execute the insert statement.

OleDbData Adapter – DataSet, DataView.

OleDbDataAdapter class is the interface between database engine and visual basic, it is the bridge between backend and frontend. This class brings the concept like dataSet and DataView.  We will discuss all these concepts 

Dataset

DataSet represents the offline/ local view of the database tables, that means no data connection necessary for accessing the fetched Dataset collection. 
DataSet object can fill with Fill Method of Adapter as follows
Dim adapter As OleDbDataAdapter = New OleDbDataAdapter(“select * from product_Registration“, Company)       
 Dim dataset As DataSet = New DataSet()       
adapter.Fill(dataset, “table1”)       
DataGridView1.DataSource = dataset
DataGridView1.DataMember = “product_Registration


The dataset can be used to fill DataGrid view too.

DataView

DataView object as the name indicate provides the table view. It can be useful when interact with the table rows.

 Dim dv As DataView
        dv = New DataView(dataset.Tables(“product_Registration”))
        adapter.Fill(dataset, “table1”)
        Dim c As Integer
        c = 0
        Do While c < dv.Count
            Console.WriteLine(dv(c).Item(0).ToString)
            c = c + 1
        Loop
   

I think you got the topic

VB.Net tutorial: How to add all columns to of table into Listview in VB.Net


How to add all column names into a listview Column header in VB.Net, here is my complete tutorial for you

Add new fields to Access table using VB6


Let me show how to add a new field into an existing access database using Visual Basic 6.0.Using the tableDef and Filed object you can create new fields. Firstly, you need to create Database and Recordset object, mke sure the DAO access object library. Continue reading Add new fields to Access table using VB6

How to auto complete text box in VB6


How to add a auto complete feature in Microsoft Visual Basic 6 ?

With the help of some creepy code, we can save the entry into a data file temporarily and later we can use them as input for auto complete the name/place/text.

The code is work with Text box as well as Combo box. Drop the following code to a module call the methods defined. Continue reading How to auto complete text box in VB6

Access and input data from MSFlexgrid control in VB6


Here is how you can input and retrieve data into and from Microsoft Flex  gridcontol in Visual Basic 6, just drag and drop and text box and flex grid. and do these code Continue reading Access and input data from MSFlexgrid control in VB6

Delete selected (treeview) rows from data table in Visual basic 6.0


How to delete selected items from a data table (Access) in Visual basic 6.0 ? Users can select the item using a list view control.

Get the count of selected items first Continue reading Delete selected (treeview) rows from data table in Visual basic 6.0