1.11M Members

Populating ComboBox using MySQL in VB.Net

 
0
 

Hello,

I need to populate my ComboBox in VB.Net using MySQL.

Can anyone help me to start.

I have created a combo box which should contain the patient name from the database.
I am using MySQL database.

Please help me in this.

Regards,
Pooja

 
0
 

So, I guess you also have a textbox where the name is entered and a button to submit the search. In the button click function take the name entered into the textbox and make that part of your SQL query (SELECT patientName FROM tableName WHERE patientName LIKE '?name' - where ?name is the parameter).

Then return the rows from the database in a dataTable and bind the datatable to your combobox using the dataSource and dataBind functions.

 
0
 

Try this

Public Function Populatecombo(ByVal TABLENAME As String, ByVal fldName As String, ByVal cmbname As ComboBox)
        Connection.Open()
        cmd = New SqlCommand("select " & fldName & " from " & TABLENAME & " order by " & fldName, lsdquescon)
        dr = cmd.ExecuteReader
        cmbname.Items.Clear()
        Do While dr.Read()
            cmbname.Items.Add(dr(fldName))
        Loop
        dr.Close()
        Connection.Close()
        Return 0
    End Function

Use Connection as ur connection string

 
0
 

Hello Poojavb !
you can use following code to populate your combobox

dim mycon as new sqlconnection (your connection string)
dim mydataset as new dataset
dim bindingsource1 as new bindingsource
mycon.open()
dim da as new sqldataadapter("select patientname from patient",mycon)
mydataset.table("Patient").clear
da.fill(mydataset,"patient")
bindingsource1.datasource = mydataset.table("patient")
combobox1.datasource = bindingsource
combobox1.displaymember = "PatientName"
bindingsource1.datasource =

hope this will help u :)
Regards
M.waqas Aslam

Question Answered as of 2 Years Ago by hericles, bhagawatshinde and M.Waqas Aslam
 
0
 

Hello Poojavb !
you can use following code to populate your combobox

dim mycon as new sqlconnection (your connection string)
dim mydataset as new dataset
dim bindingsource1 as new bindingsource
mycon.open()
dim da as new sqldataadapter("select patientname from patient",mycon)
mydataset.table("Patient").clear
da.fill(mydataset,"patient")
bindingsource1.datasource = mydataset.table("patient")
combobox1.datasource = bindingsource
combobox1.displaymember = "PatientName"
bindingsource1.datasource =

hope this will help u :)
Regards
M.waqas Aslam

Thanks to all

I did it this way

Dim conn As New SqlConnection(ConnectionString)
        Dim strSQL As String = "SELECT distinct PatientID,PatientName FROM Pat_Doc_Pro"
        Dim da As New SqlDataAdapter(strSQL, conn)
        Dim ds As New DataSet
        da.Fill(ds, "Pat_Doc_Pro")
        With cboPatientID
            '  .Items.Add("Select")
            .DataSource = ds.Tables("Pat_Doc_Pro")
            .DisplayMember = "PatientName"
            .ValueMember = "PatientID"
            .SelectedIndex = 0
        End With
Isn't it about time forums rewarded their contributors?

Earn rewards points for helping others. Gain kudos. Cash out. Get better answers yourself.

It's as simple as contributing editorial or replying to discussions labeled or OP Kudos

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article