Hello all,
I want to get items into the ListBox from Database on FormLoad.
My code is:
database Code:
Private Sub Models_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim qry As String qry = "SELECT model FROM models" Dim sqlcon As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=D:\My Personal\VB Projects\Mobile Repairing\Mobile Repairing\repairs.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True") Dim sqlcmd As New SqlCommand(qry, sqlcon) Dim dr As SqlDataReader sqlcon.Open() dr = sqlcmd.ExecuteReader dr.Read() If dr.HasRows Then While dr.Read() ModelListBox.Items.Add(ToString) End While End If dr.Close() sqlcon.Close() End Sub
I am already having three models in database that has to be loaded in ListBox on formload.
Any help will be appreciated.
Thanks in advance.
Trusted




and rate if you like this post
Reply With Quote