Solved

reader.read not working...

Posted on 2008-10-22
3
941 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
Comment Utility
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 142

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 100 total points
Comment Utility
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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video discusses moving either the default database or any database to a new volume.

744 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now