How to Save and Fill Data in a ComboBox Two Display Members in

How to Save and Fill Data in a ComboBox Two Display Members in

This tutorial is all about How to Save and Fill the Data in a ComboBox With Two Display Members in
In this tutorial, I will show you how to save and fill data in the combobox with two display members using Visual Basic 2008 and Ms Access Database. Displaying two members in the ComboBox is very easy, all you need is a concatenation function in a query.

What is Visual Basic’s purpose?

The third-generation programming language was created to aid developers in the creation of Windows applications. It has a programming environment that allows programmers to write code in.exe or executable files. They can also utilize it to create in-house front-end solutions for interacting with huge databases. Because the language allows for continuing changes, you can keep coding and revising your work as needed.

However, there are some limits to the Microsoft Visual Basic download. If you want to make applications that take a long time to process, this software isn’t for you. That implies you won’t be able to use VB to create games or large apps because the system’s graphic interface requires a lot of memory and space. Furthermore, the language is limited to Microsoft and does not support other operating systems.

What are the most important characteristics of Visual Basic?

Microsoft Visual Basic for Applications Download, unlike other programming languages, allows for speedier app creation. It has string processing capabilities and is compatible with C++, MFC, and F#. Multi-targeting and the Windows Presentation Framework are also supported by the system, allowing developers to create a variety of Windows apps, desktop tools, metro-style programs, and hardware drivers.

Concatenation is a function that joins two or more fields in the table of the Ms Access Database.

The concatenation in the MS Access Database is, you have to put an operator (&) to concat the two or more fields.

To start with:

Open the Visual Basic 2008, create a new Windows Form Application. After that, add four Labels, two TextBoxes, button and a ComboBox. In the ComboBox, it is where you display the two fields in the table of Ms Access database and the two textBoxes, is where you write the records that will be saved in Ms Access database.


Double click the Form and do this code for the connection of MS Access Database to Visual Basic 2008 above the Form1_Load.

‘connection of MS Access Database to Visual Basic 2008
Dim con As OleDb.OleDbConnection = New _
OleDb.OleDbConnection(“Provider=Microsoft.ACE.OLEDB.12.0;Data Source=” _
& Application.StartupPath & “\test.accdb”)

‘declaring the classes
‘OleDbDataAdapter represents a set of data command and
‘ the database that are use to update and fill the data source
Dim da As OleDb.OleDbDataAdapter
Dim ds As DataSet ‘represent a cache in memory of data

Description : OleDb is a namespace of a class. Application in the application.startpath is providing the static method to manage the application. Startpath in the application.startpath is getting the executive file.

In the Form1_Load, do this code for filling the data in the ComboBox that has two display members.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
‘filling the data of a combobox in the first load
‘openning the connection
‘in this area, it is where the command happens for filling
‘and updating data in the database
‘and also the concatenation of a query.
da = New OleDb.OleDbDataAdapter(“SELECT ID,(fname & ‘ ‘ & lname) as [Name] from member “, con)
ds = New DataSet

‘refreshes the row into the dataset
‘to match those data in the table
da.Fill(ds, “test”)
‘defining what are the attributes of a combo box
With ComboBox1
‘set the data source to this combo box
.DataSource = ds.Tables(0)
‘set the fields of the table to display in a list control
.DisplayMember = “Name”
‘set the actual value of a combo box
.ValueMember = “ID”
End With
‘closing the connection
End Sub

And this code is for storing the data in the database.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
‘for data storing
‘openning connection
da = New OleDb.OleDbDataAdapter(“INSERT INTO member (fname,lname) VALUES (‘” & TextBox1.Text & “‘,'” & TextBox2.Text & “‘)”, con)
ds = New DataSet
‘closing the connection
‘calling the first load to refresh the record in the combo box
Call Form1_Load(sender, e)
End Sub

The database of this file is in the bin. You can download the complete Source Code.


Readers might read also:

Leave a Comment