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
Solved

reader.read not working...

Posted on 2008-10-22
3
950 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
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

839 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