Solved

reader.read not working...

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

920 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

16 Experts available now in Live!

Get 1:1 Help Now