Show Record Data Database In ComboBox VB 2013

2:09:00 PM

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


Artikel Terkait

Next Article
« Prev Post
Previous Article
Next Post »
Penulisan markup di komentar
  • Untuk menulis huruf bold silahkan gunakan <strong></strong> atau <b></b>.
  • Untuk menulis huruf italic silahkan gunakan <em></em> atau <i></i>.
  • Untuk menulis huruf underline silahkan gunakan <u></u>.
  • Untuk menulis huruf strikethrought silahkan gunakan <strike></strike>.
  • Untuk menulis kode HTML silahkan gunakan <code></code> atau <pre></pre> atau <pre><code></code></pre>, dan silahkan parse dulu kodenya pada kotak parser di bawah ini.
Konversi Code
Disqus
Silahkan Berkomentar Dengan