Hi I am having a very frustrating problem with a DropDownList. The DropDownList is bound to one SQL Server 2005 table. I do this progromatically with the following code:
Public Sub EvaltrID() TryDim aType As String = txtAircraftType.SelectedValue Dim auth As String = Convert.ToInt32(MinLevel.Text) Dim active As String = "True" Dim iPilot As String = "True"Dim CrewPos As String = txtCrewPos.SelectedValue Dim CrewPos1 As String = "SO" Dim instructSO As String = "True"Dim sesType As String = txtSessionType.Text Dim sesType1 As String = "aqplc" Dim sesType2 As String = "lc"Dim program As String = txtProgram.Text Dim program1 As String = "cq" Dim program2 As String = "qc"Dim oConn As SqlConnection Dim oComm As SqlCommandDim oReader As SqlDataReader Dim sSQL As String Dim sConn As StringsSQL =
"SELECT EvaltrID, convert(varchar, EvaltrID) + ' ' + LastName + ', ' + FirstName as info, AircraftType, IsActive, InstructorPilot, InstructorSO, [Authorization] FROM tlkpEvaltrID WHERE AircraftType = '" & aType & "' And [Authorization] >= " & auth & " And IsActive = '" & active & "' And InstructorPilot= '" & iPilot & "' And '" & CrewPos & "' <> '" & CrewPos1 & "' Or AircraftType='" & aType & "' And [Authorization] >= " & auth & " And IsActive = '" & active & "'And InstructorSO = '" & instructSO & "'And '" & CrewPos & "' = '" & CrewPos1 & "'And '" & sesType & "' <> '" & sesType1 & "'Or AircraftType = '" & aType & "'And [Authorization] >= " & auth & " And IsActive = '" & active & "'And InstructorPilot = '" & iPilot & "' And '" & CrewPos & "' = '" & CrewPos1 & "'And '" & sesType & "' = '" & sesType1 & "'Or '" & sesType & "' = '" & sesType2 & "'And '" & program & "' = '" & program1 & "'Or '" & program & "' = '" & program2 & "' ORDER BY LastName"sConn = ConfigurationManager.ConnectionStrings("svtppdbSQLConnectionString2").ConnectionStringoConn = New SqlConnection(sConn)
oConn.Open()
ddlEvaltrID.DataTextField =
"info"ddlEvaltrID.DataValueField =
"EvaltrID"oComm = New SqlCommand(sSQL, oConn)oReader = oComm.ExecuteReader()
ddlEvaltrID.DataSource = oReader
ddlEvaltrID.DataBind()
oConn.Close()
Catch ex As ExceptionlblMessage.Text = ex.Message
End TryEnd Sub
I then use a DataReader to choose a selected value for the DropDownList when the page loads. This value comes from another table.
Dim conn As SqlConnection Dim sqlCmd As SqlCommand Dim Reader As SqlDataReaderconn =
New SqlConnection(ConfigurationManager.ConnectionStrings("svtppdbSQLConnectionString2").ConnectionString)sqlCmd =
New SqlCommand("SELECT * from tblSession where SessionID='" & inputnumber1 & "'", conn)conn.Open()
Reader = sqlCmd.ExecuteReader(CommandBehavior.CloseConnection)
Reader.Read()
If Reader.HasRows ThenIf
Reader("PilotEvaltrID") Is DBNull.Value And (txtCrewPos.SelectedValue = "CA" Or txtCrewPos.SelectedValue = "FO") Then ElseddlEvaltrID.SelectedValue = Reader("PilotEvaltrID")ddlEvaltrID.Enabled =
False End IfEnd If
I am having such a hard time with this. I'm getting this error message: 'ddlEvaltrID' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value. I know what this means. I know that it means that PilotEvaltrID column does not exist in the data that is currently bound to the DropDownList. But, I'm unsure what to do. Should I use a join statement? I've found a ton of info on this in this forum, but nothing that helps me with the particular situation I face. Does anyone have any advice for me?? Thanks.
Holly Quinn
http://www.hollyquinn.com/Blog
![]() |
0 |
![]() |
Why don't you do a join when running your query and set the text and value at the same time?
Joseph Baggett
MCSD, MCPD: Web Developer, MCITP: Database Developer, MCTS: SQL Server 2005, MCTS: .NET 2.0 Web Applications, MCTS: .NET Framework 2.0 Windows Applications, MCTS: .NET Framework 2.0 Windows Applications, MCAD, MCP
If the project doesn't work, blame Scott Guthrie and/or refer to the problem solving flowsheet. O.~
![]() |
0 |
![]() |
Joseph Baggett:
Why don't you do a join when running your query and set the text and value at the same time?
I did try doing a join but I got the same error. Here's the code I wrote for that. Am I doing it incorrectly?
sqlCmd =
New SqlCommand("select tlkpEvaltrID.LastName, tlkpEvaltrID.FirstName, tlkpEvaltrID.EvaltrID, tblSession.PilotEvaltrID, tblSession.SessionID from tlkpEvaltrID Inner Join tblSession on tlkpEvaltrID.EvaltrID = tblSession.PilotEvaltrID where tblSession.SessionID= '" & inputnumber1 & "'", conn)conn.Open()
Reader = sqlCmd.ExecuteReader(CommandBehavior.CloseConnection)
Reader.Read()
If Reader("PilotEvaltrID") Is DBNull.Value And (txtCrewPos.SelectedValue = "CA" Or txtCrewPos.SelectedValue = "FO") Then ElseddlEvaltrID.SelectedValue = Reader("EvaltrID")ddlEvaltrID.Enabled =
False End IfReader.Close()
conn.Close()
Holly Quinn
http://www.hollyquinn.com/Blog
![]() |
0 |
![]() |