Hi, I have this sub which populate to a drop down list for state in my registration form. It works but in my registration form, I have a few state which need to populate the same value. What's the best way to go about it without repeating many codes?
Private Sub PopulateState()
cboState.AppendDataBoundItems = True
Dim strConnString As String = ConfigurationManager.ConnectionStrings("LoginDBConn").ConnectionString
Dim strQuery As String = "SELECT statename FROM State"
Dim con As New SqlConnection(strConnString)
Dim cmd As New SqlCommand()
cmd.CommandType = CommandType.Text
cmd.CommandText = strQuery
cmd.Connection = con
Try
con.Open()
cboState.DataSource = cmd.ExecuteReader()
cboState.DataTextField = "statename"
cboState.DataValueField = "statename"
cboState.DataBind()
Catch ex As Exception
Throw ex
Finally
con.Close()
con.Dispos ...
Go to the complete details ...