I have an ASP.Net web page that retrieves state abbreviations as the values from a querystring. I have a desire to display the full state name in the title of the web page. I want to be able to retrieve the datafield from the table before I create a label control to display it. I have tried several different things, but I have been unsuccessful so far. Can someone please look at my code and see how I might be able to solve this problem? I have bolded the important parts of this code.
Here's the error message that I got:
Compiler Error Message: BC30367: Class 'System.Data.SqlClient.SqlDataAdapter' cannot be indexed because it has no default property.
Source Error:
|
Line 61:
Line 62: 'Set module level variable for page title display
Line 63: FullState = dtaSpa("StateName") & ""
|
Here's my code:
'---------------------------------------------
' name: BindDataList()
'---------------------------------------------
Sub BindDataList()
Dim strConnect As String
Dim objConnect As New System.Data.SqlClient.SQLConnection(ConnectionString())
Dim objCommand As New System.Data.SqlClient.SQLCommand
Dim strSQL as String
Dim dtaSpa As New System.Data.SqlClient.SQLDataAdapter()
Dim dtsSpa As New DataSet()
Dim strChosenState as String
Dim FullState as String
objConnect.Open()
'Get incoming querystring values
strChosenState = request.params("State")
'Start SQL statement
strSQL = "Select * From Area, State"
strSQL = strSQL & " where Area.State = State.State"
strSQL = strSQL & " and Area.State = '" & strChosenState & "'"
strSQL = strSQL & " Order By Area"
Trace.Warn ("strSQL = " & strSQL)
'Set the Command Object properties
objCommand.Connection = objConnect
objCommand.CommandType = CommandType.Text
objCommand.CommandText = strSQL
'Create a new DataAdapter object
dtaSpa.SelectCommand = objCommand
'Get the data from the database and
'put it into a DataTable object named dttSpa in the DataSet object
dtaSpa.Fill(dtsSpa, "dttSpa")
'Set the DataSource property of the DataGrid
dtlSpa.DataSource = dtsSpa
'Set module level variable for page title display
FullState = dtaSpa("StateName") & ""
'Bind all the controls on the page
dtlSpa.DataBind()
'Display chosen StateName
'lblState.Text = "Chosen Category: " & strChosenState
'Show chosen category in our navigation breadcrumb
'lblChosenCategory.Text = strChosenCategory
'Display category choice in page title
'litTitle.Text = "Find a Spa Store For " & FullState
End Sub