Hello. I am very new to .NET programming, so my question is probably easy to answer. Or, maybe someone can direct me to the web source where I will be able to find the solution. Anyway, I need to populate a drop-down list with the results from the stored procedure. I was able to write a partially working code, but still have two problems. The first one is that my procedure returns multiple record sets, and I need to have some kind of a loop to append all of them to each other and load all information into the drop-down. Something like this code in ASP:
Do Until rsQuery is Nothing
RunProcedure = RunProcedure & rsQuery.GetString()
Set rsQuery = rsQuery.Nextrecordset
Loop
The second problem is that if I load the first record set and test the page, the value selected in this drop-down will not be recognized by another stored procedure where I pass it as a parameter. Here is the code I have for the Page_Load event. I believe my problem is somewhere in the highlighted part, but not sure where.
Try
'Refer to the connection in web.config
strConnection = ConfigurationSettings.AppSettings("WebConfConn")
'Connect to the database
sqlConn = New SqlConnection(strConnection)
'Create a command string
strCmd = "DB_SP_DisplayNames"
'Create a command
sqlCmd = New SqlCommand(strCmd, sqlConn)
sqlCmd.CommandType = CommandType.StoredProcedure
'Open Connection
sqlConn.Open()
'Set Data Reader
sqlReader = sqlCmd.ExecuteReader()
'Get data from the Data Reader and load it to the drop-down list
ddlName.DataSource = sqlReader
ddlName.DataTextField = "sName"
ddlName.DataValueField = "sName"
ddlName.DataBind()
Catch ex As Exception
Response.Write(ex.ToString & "<br>")
Finally
sqlReader.Close()
sqlConn.Close()
End Try
Thank you in advance for all your help.
Do Until rsQuery is Nothing
RunProcedure = RunProcedure & rsQuery.GetString()
Set rsQuery = rsQuery.Nextrecordset
Loop
The second problem is that if I load the first record set and test the page, the value selected in this drop-down will not be recognized by another stored procedure where I pass it as a parameter. Here is the code I have for the Page_Load event. I believe my problem is somewhere in the highlighted part, but not sure where.
Try
'Refer to the connection in web.config
strConnection = ConfigurationSettings.AppSettings("WebConfConn")
'Connect to the database
sqlConn = New SqlConnection(strConnection)
'Create a command string
strCmd = "DB_SP_DisplayNames"
'Create a command
sqlCmd = New SqlCommand(strCmd, sqlConn)
sqlCmd.CommandType = CommandType.StoredProcedure
'Open Connection
sqlConn.Open()
'Set Data Reader
sqlReader = sqlCmd.ExecuteReader()
'Get data from the Data Reader and load it to the drop-down list
ddlName.DataSource = sqlReader
ddlName.DataTextField = "sName"
ddlName.DataValueField = "sName"
ddlName.DataBind()
Catch ex As Exception
Response.Write(ex.ToString & "<br>")
Finally
sqlReader.Close()
sqlConn.Close()
End Try
Thank you in advance for all your help.