sql-count in webform

R

ReidarT

I have 3 comboboxes with country, county/state and city.
I want to count county/states to diasble the county/state-combobox when
there is a country with no county/states
My code is
cn.Open()
Dim sqlCounty As String = "SELECT DISTINCT County FROM HotelAll_tbl"
If ddlCountry.SelectedIndex >= 0 Then
sqlCounty &= " WHERE Country = '" & ddlCountry.SelectedItem.Text
& "'"
sqlCounty &= "ORDER BY County ASC"
End If
Dim cmdCounty As New SqlCommand(sqlCounty, cn)
Dim drCounty As SqlDataReader = cmdCounty.ExecuteReader()
ddlCounty.DataSource = drCounty
ddlCounty.DataTextField = "County"
ddlCounty.DataBind()
drCounty.Close()

Here is my attempt to count the counties/states
'Antall counties
Dim intCountCounty As Integer
Dim sqlCountCounty As String = "SELECT count(County) as CountCounty
FROM HotelAll_tbl"
sqlCountCounty &= " WHERE Country = '" &
ddlCountry.SelectedItem.Text & "'"
Dim cmdcountCounty As New SqlCommand(sqlCountCounty, cn)
Dim drcountCounty As SqlDataReader = cmdcountCounty.ExecuteReader()
'intCountCounty = drcountCounty.GetSqlValue
....
Stop my attempt

cn.Close()
ddlCounty.Items.Insert(0, "--Select county--")
I want the number of county/states in the intCountyState dim.
regards
reidarT
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,141
Messages
2,570,815
Members
47,361
Latest member
RogerDuabe

Latest Threads

Top