I have a drop down list for cities, and I have cities in my database that I want to populate to a drop down list.
On the Page load made an sql connection
Dim s As String = "Connection String"
sqlconn = New SqlConnection(s)
Now on the drop down load I have a query which is working fine. How to add results from the database query to the drop down?
Protected Sub Citydropdown_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Citydropdown.Load
sqlCmd = New SqlCommand("select City from usrRegister_aunthentication", sqlconn)
If sqlconn.State = Data.ConnectionState.Closed Then
sqlconn.Open()
End If
Dim i As String = sqlCmd.ExecuteReader()
If sqlconn.State = Data.ConnectionState.Open Then
sqlconn.Close()
End If
End Sub
Also, sometimes the same city is repeated. How do I only show each city once?