We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

2 dropdownlist

hi

I hope some one help me , i use two dropdownlist in the same webform and each DDL gets data from differents tables SQL database. How can i write VB code

1 Reply

PJ Poornima Joy Balan Syncfusion Team October 8, 2007 06:33 AM UTC

Hello,

The following code snippet helps you to add the data's from different table to DDL

Dim connString As String = "Provider=SQLOLEDB.1;User ID=yourid;Password=yourpassword;Persist Security Info=True;Network Address=yourIP;Initial Catalog=databasename"
Dim conn As New OleDbConnection(connString)
conn.Open()
Dim cmd As New OleDbCommand("select * from table1", conn)
cmd.CommandTimeout = 180

Dim da As New OleDbDataAdapter(cmd)
Dim ds As New DataSet()
da.Fill(ds)
List1.DataSource = ds.Tables(0)
List1.DataTextField = "Empname"
List1.DataValueField = "Empname"
List1.DataBind()

Dim cmd2 As New OleDbCommand("select * from table2", conn)
cmd2.CommandTimeout = 180

Dim da2 As New OleDbDataAdapter(cmd)
Dim ds2 As New DataSet()
da2.Fill(ds2)
List2.DataSource = ds.Tables(0)
List2.DataTextField = "category_id"
List2.DataValueField = "cname"
List2.DataBind()
conn.Close()

Let me know, any further queries.

Regards,
Poornima

Loader.
Live Chat Icon For mobile
Up arrow icon