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
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
Next Article
« Prev Post
« Prev Post
Previous Article
Next Post »
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
Silahkan Berkomentar Dengan