Show Record Data Database In ComboBox VB 2013


In this tutorial I will share about : how to Show Record Data Database In ComboBox VB NET 2013. in this step below I use database SQL Server. if you dont have SQL Server please prepare to install SQL Server.

Please following below :
#1. Create Database and Table using SQL Server
Create Database : DB_MYAPP
Create Table : TBL_PRODUCT with design table like below picture

Fill sample data in TBL_PRODUCT


See also : How to Show Date and Time in Form VB Net 2013

#2. Design Form and Place a Code

Fill Below code at Form1.vb

Imports System.Data.SqlClient
Public Class Form1
    Dim Conn As SqlConnection
    Dim da As SqlDataAdapter
    Dim ds As DataSet
    Dim CMD As SqlCommand
    Dim RD As SqlDataReader
    Dim DBLocation As String
    Sub Show_tbl_data()
        Call OpenDB()
        ComboBox1.Items.Clear()
        CMD = New SqlCommand("select * FROM TBL_PRODUCT", Conn)
        RD = CMD.ExecuteReader
        Do While RD.Read
            ComboBox1.Items.Add(RD.Item(0))
        Loop
    End Sub
    Sub OpenDB()
        DBLocation = "data source=COMPUTERNAME;initial catalog=DB_MYAPP;integrated security =true"
        Conn = New SqlConnection(DBLocation)
        If Conn.State = ConnectionState.Closed Then Conn.Open()
    End Sub
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        OpenDB()
        da = New SqlDataAdapter("Select * from TBL_PRODUCT", Conn)
        ds = New DataSet
        ds.Clear()
        da.Fill(ds, "TBL_PRODUCT")
        DataGridView1.DataSource = (ds.Tables("TBL_PRODUCT"))
        Call Show_tbl_data()
    End Sub
End Class

Please start or run your project, thanks for visiting BelajarVB and dont forget to comment below


Subscribe to receive free email updates:

0 Response to "Show Record Data Database In ComboBox VB 2013"

Post a Comment