locked
System.IndexOutOfRangeException RRS feed

  • Question

  • User1271089328 posted
    I am trying to pull optionid to toggle the checkbox, but I get an error:"System.IndexOutofRangeException" When I test my sql statement in query analyzer, it pulls data ok, so I'm not sure why I'm getting the error. Any help would be greatly appreciated. Thanks in advance! Here is my code: If Not IsPostBack Then txtTotal.Text = CInt(49.99) If Session("CustomerID") <> "" Or Not (Session("CustomerID") Is Nothing) Then SqlConnOptions.Open() Dim strComm As String Dim i As Integer strComm = "Select customerid, orders.orderid, options.optiondesc, options.optioncost, " & _ " options.installcharge from Orders " & _ " inner join Order_options on orders.orderid = order_options.orderid " & _ " inner join options on options.optionsid = order_options.optionsid " & _ " where orders.customerid = " & Session("CustomerID") Dim sqlComm As New SqlClient.SqlCommand(strComm, SqlConnOptions) Dim dreader As SqlClient.SqlDataReader dreader = sqlComm.ExecuteReader dreader.Read() Select Case dreader("optionsid") Case 1 ChkCID.Checked = True Case 2 ChkCW.Checked = True Case 3 ChkUP.Checked = True End Select End If End If End Sub
    Tuesday, October 7, 2003 1:06 PM

All replies

  • User-1937548964 posted
    I don't see optionsid among the select fields. Also you should place dreader.Read() in a conditional statement so that it only will try to read if there is a record. strComm = "Select customerid, options.optionsid, orders.orderid, options.optiondesc, options.optioncost, " & _ " options.installcharge from Orders " & _ " inner join Order_options on orders.orderid = order_options.orderid " & _ " inner join options on options.optionsid = order_options.optionsid " & _ " where orders.customerid = " & Session("CustomerID") Dim sqlComm As New SqlClient.SqlCommand(strComm, SqlConnOptions) Dim dreader As SqlClient.SqlDataReader dreader = sqlComm.ExecuteReader If dreader.Read() Then Select Case dreader("optionsid") Case 1 ChkCID.Checked = True Case 2 ChkCW.Checked = True Case 3 ChkUP.Checked = True End Select End If
    Tuesday, October 7, 2003 1:36 PM