Solved

reader.read not working...

Posted on 2008-10-22
3
958 Views
Last Modified: 2013-11-08
I have a pretty basic reader that is not working properly.  While debugging, I put a breakpoint in the selectedindexchanged event of a dropdown list, the entire operation is working, however my If statement is not being read.

the snippit below is where the issue is, the debugger hits the line "While readerType.Read and then jumps down to End While.

I am due to present this process in about an hour, hopefully this is just a simple fix...ugh.
Using conType
                conType.Open()
                Dim readerType As SqlDataReader = cmdType.ExecuteReader()
                While readerType.Read
                    If Not IsDBNull(readerType.Item(0)) Then
                        intType = readerType.Item(0)
                        Me.DropDownListReplacementType.SelectedValue = intType
                        DropDownListReplacementType_SelectedIndexChanged()
                        Me.DropDownListReplacementMake.DataBind()
                        If Not IsDBNull(readerType.Item(1)) Then
                            intMake = readerType.Item(1)
                            Me.DropDownListReplacementMake.SelectedValue = intMake
                            DropDownListReplacementMake_SelectedIndexChanged()
                            Me.DropDownListReplacementModel.DataBind()
                            If readerType.Item(2) = "" Then
                            Else
                                intModel = readerType.Item(2)
                                DropDownListReplacementModel.SelectedValue = intModel
                            End If
                        End If
                    End If
                End While
                conType.Close()
            End Using

Open in new window

0
Comment
Question by:cwickens
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 53

Accepted Solution

by:
Dhaest earned 300 total points
ID: 22775035
Can you check the command of cmdType.ExecuteReader()
Probably the query doesn't return any data and then offcourse, the while will be skipped
0
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 100 total points
ID: 22775159
if the readerType.Read returns false on the first loop, that means you have no records in the (first) recordset.
what is the cmdType.CommandType and CommandType?
if it's a stored procedure, does it have some SET, SELECT, INSERT, DELETE, UPDATE before the actual SELECT ?
if yes, add the SET NOCOUNT ON in the procedure body.
0
 
LVL 13

Assisted Solution

by:TechTiger007
TechTiger007 earned 100 total points
ID: 22775236
check if your reader has results before calling read on it


if readerType.HasRows then

While readerType.Read
                    If Not IsDBNull(readerType.Item(0)) Then
                        intType = readerType.Item(0)
                        Me.DropDownListReplacementType.SelectedValue = intType
                        DropDownListReplacementType_SelectedIndexChanged()
                        Me.DropDownListReplacementMake.DataBind()
                        If Not IsDBNull(readerType.Item(1)) Then
                            intMake = readerType.Item(1)
                            Me.DropDownListReplacementMake.SelectedValue = intMake
                            DropDownListReplacementMake_SelectedIndexChanged()
                            Me.DropDownListReplacementModel.DataBind()
                            If readerType.Item(2) = "" Then
                            Else
                                intModel = readerType.Item(2)
                                DropDownListReplacementModel.SelectedValue = intModel
                            End If
                        End If
                    End If
                End While
end if
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question