Latest posts by Sana Modi (see all)
- 80s Happy Birthday Song Download - January 4, 2023
- Traditional Happy Birthday Song Download - December 28, 2022
- The Best VPN For Netflix-2022 - December 17, 2022
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.
Module:
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
Form:
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