Katya85S
Programmer
- Jul 19, 2004
- 190
Perhaps somebody can help… In asp.net project (VB.net) I want to populate a dropdownlist, lst1, with a value from SQL Query, using SLQDataReader object.
strSQL=”SELECT AppName, EmpNum FROM tblApp WHERE AppID=” & iAppID
myConn.Open()
Dim objCmd As New SqlCommand(strSQL, myConn)
Dim objDR As SqlDataReader
objDR = objCmd.ExecuteReader(CommandBehavior.CloseConnection)
If objDR.Read Then
lstEmpIT.SelectedValue = objDR("EmpNum")
end if
This code results in an error message:
“'lst1' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value”
I’ve trouble-shoot the objDR(“EmpNum”) to find out its value:
lblMessage.Text = objDR("EmpNum")
This returned value “00345”.
When I hard-coded the value into the code:
lstEmpIT.SelectedValue = “00345”
the application workes fine, populating the correct item into the dropdownlist lst1.
What could be wrong with objDR(“EmpNum”) and how can I fix the situation?
I would appreciate any advice.
Thank you all in advance.
strSQL=”SELECT AppName, EmpNum FROM tblApp WHERE AppID=” & iAppID
myConn.Open()
Dim objCmd As New SqlCommand(strSQL, myConn)
Dim objDR As SqlDataReader
objDR = objCmd.ExecuteReader(CommandBehavior.CloseConnection)
If objDR.Read Then
lstEmpIT.SelectedValue = objDR("EmpNum")
end if
This code results in an error message:
“'lst1' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value”
I’ve trouble-shoot the objDR(“EmpNum”) to find out its value:
lblMessage.Text = objDR("EmpNum")
This returned value “00345”.
When I hard-coded the value into the code:
lstEmpIT.SelectedValue = “00345”
the application workes fine, populating the correct item into the dropdownlist lst1.
What could be wrong with objDR(“EmpNum”) and how can I fix the situation?
I would appreciate any advice.
Thank you all in advance.