Solved

reader.read not working...

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

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Web site error 3 36
encoding an href string 2 20
How to parse the string and split the sub directory names in asp.net 7 38
ASP.NET MVC identity 6 26
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

786 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