Sana Modi is a technology expert and content writer at nosware. She has a tremendous knowledge of the latest social sites apart from social media, she also examined the latest games and laptops and has personally reviewed the products. She loves to explore all the social media sites and research them.
Last Updated on November 10, 2022 by Humera hallari
Here the code if you want to get two values from database, and show in Combobox item in Visual Basic VB.NET.
Imports MySql.Data.MySqlClient Public Class DTConnection Dim conect As New MySqlConnection("server=localhost; user=root; password=; database=combobox_db;") Public Function Open() As MySqlConnection Try conect.Open() Catch ex As Exception MsgBox(ex.Message) End Try Return conect End Function Public Function Close() As MySqlConnection Try conect.Close() Catch ex As Exception MsgBox(ex.Message) End Try Return conect End Function End Class
Imports MySql.Data.MySqlClient Public Class Form1 Dim mycmd As New MySqlCommand Dim myconnection As New DTConnection Dim objdatareader As MySqlDataReader Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load myconnection.Close() mycmd = myconnection.Open.CreateCommand mycmd.CommandText = "select number,description from tbdetail" objdatareader = mycmd.ExecuteReader While objdatareader.Read ComboBox1.Items.Add("[" & objdatareader(0) & "]" & " - " & objdatareader(1)) ComboBox1.ValueMember = objdatareader(0) End While myconnection.Close() End Sub End Class