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
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
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.
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
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
Hello Poojavb !
you can use following code to populate your comboboxdim 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
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.