473,383 Members | 1,853 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Why does this code not work???

Here's my function. I keep getting 'Object not set to an
instance of an object when I call myDR.Read. (I'm using
the Application Data blocks v1). I have similar routines
throughout this project that work - I don't see any code
differences. Any suggestions???

Private Function GetOrderSessionId(ByVal OrderId As
Integer) As String

Dim myDR As SqlDataReader
myDR = SqlHelper.ExecuteReader
(ConfigurationSettings.AppSettings("connectionStri ng"), _
CommandType.Text, "Select SessionId from
Orders where OrderId = " & OrderId)

If myDR.Read = True Then 'ERROR HERE
Return myDR("SessionId")
End If
myDR.Close()

End Function
Jul 21 '05 #1
4 1574
What is SQLHelper? Your errro probably orginates there.
"Kelly E" <an*******@discussions.microsoft.com> wrote in message
news:14*****************************@phx.gbl...
Here's my function. I keep getting 'Object not set to an
instance of an object when I call myDR.Read. (I'm using
the Application Data blocks v1). I have similar routines
throughout this project that work - I don't see any code
differences. Any suggestions???

Private Function GetOrderSessionId(ByVal OrderId As
Integer) As String

Dim myDR As SqlDataReader
myDR = SqlHelper.ExecuteReader
(ConfigurationSettings.AppSettings("connectionStri ng"), _
CommandType.Text, "Select SessionId from
Orders where OrderId = " & OrderId)

If myDR.Read = True Then 'ERROR HERE
Return myDR("SessionId")
End If
myDR.Close()

End Function

Jul 21 '05 #2
SqlHelper is the MS Application Block object. The
application blocks are classes MS built to make our lives
easier in writing data access code. I use the object
everywhere in this project.
-----Original Message-----
What is SQLHelper? Your errro probably orginates there.
"Kelly E" <an*******@discussions.microsoft.com> wrote in messagenews:14*****************************@phx.gbl...
Here's my function. I keep getting 'Object not set to an instance of an object when I call myDR.Read. (I'm using the Application Data blocks v1). I have similar routines throughout this project that work - I don't see any code differences. Any suggestions???

Private Function GetOrderSessionId(ByVal OrderId As
Integer) As String

Dim myDR As SqlDataReader
myDR = SqlHelper.ExecuteReader
(ConfigurationSettings.AppSettings ("connectionString"), _ CommandType.Text, "Select SessionId from
Orders where OrderId = " & OrderId)

If myDR.Read = True Then 'ERROR HERE
Return myDR("SessionId")
End If
myDR.Close()

End Function

.

Jul 21 '05 #3
On Mon, 15 Dec 2003 08:50:10 -0800, Kelly E wrote:
Any suggestions???
Try running the SQL query in Query Analyzer. It's possible that the query
does not return anything, so the myDR datareader is null.
Dim myDR As SqlDataReader
myDR = SqlHelper.ExecuteReader
(ConfigurationSettings.AppSettings("connectionStri ng"), _
CommandType.Text, "Select SessionId from
Orders where OrderId = " & OrderId)


If you put a break point at the line above and then step through it, is the
myDR variable Nothing? Again, it sounds like your SQL query is not return
anything. Is the OrderId valid and are there items in the Orders table for
that OrderId?

Just some thoughts

--
Chris

To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
address.
Jul 21 '05 #4
Kelly,

What namespace does the SQLHelper reside, I could not find it in the help?
I use a similar pattern for returning a row or rows of data and do not have
a problem (shown below). As I suggested before the error must reside in
some where in/around SQLHelper because the reader is not properly
instantiated, (perhaps the connect string is incorrect).

Even if your query does not return rows the Reader.Read method should return
a value.

Dan

If rdr.Read() Then
...
End If

While rdr.Read
...
End While
"Kelly E" <an*******@discussions.microsoft.com> wrote in message
news:07****************************@phx.gbl...
SqlHelper is the MS Application Block object. The
application blocks are classes MS built to make our lives
easier in writing data access code. I use the object
everywhere in this project.
-----Original Message-----
What is SQLHelper? Your errro probably orginates there.
"Kelly E" <an*******@discussions.microsoft.com> wrote in

message
news:14*****************************@phx.gbl...
Here's my function. I keep getting 'Object not set to an instance of an object when I call myDR.Read. (I'm using the Application Data blocks v1). I have similar routines throughout this project that work - I don't see any code differences. Any suggestions???

Private Function GetOrderSessionId(ByVal OrderId As
Integer) As String

Dim myDR As SqlDataReader
myDR = SqlHelper.ExecuteReader
(ConfigurationSettings.AppSettings ("connectionString"), _ CommandType.Text, "Select SessionId from
Orders where OrderId = " & OrderId)

If myDR.Read = True Then 'ERROR HERE
Return myDR("SessionId")
End If
myDR.Close()

End Function

.

Jul 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Jonas | last post by:
This works fine in Win XP but does not work at all in Win 98. Private WithEvents objIExplorer As InternetExplorer I have to do it like this to get it to work in Win 98 Dim objIExplorer As...
2
by: Paul THompson | last post by:
I have a piece of code something like the following: START OF CODE <html><head><title>The Wizard</title></head> <body> <h1>Welcome to Joe's Vet Clinic</h1> <div id="part1"...
162
by: Isaac Grover | last post by:
Hi everyone, Just out of curiosity I recently pointed one of my hand-typed pages at the W3 Validator, and my hand-typed code was just ripped to shreds. Then I pointed some major sites...
5
by: me | last post by:
I have a Class Library that contains a Form and several helper classes. A thread gets created that performs processing of data behind the scenes and the Form never gets displayed (it is for debug...
4
by: rick | last post by:
The following basic script works fine in firefox by not in IE. Can anyone spot the problem? In IE I can only delete the first line but not the lines created by javascript. Also, look at the HTML...
6
by: benb | last post by:
I have form that looks a lot like a search bar for the user to search for records matching specified criteria (e.g. first names containing "ben"). For robust results, an intermediary form displays...
14
by: Anoop | last post by:
Hi, I am new to this newsgroup and need help in the following questions. 1. I am workin' on a GUI application. Does C# provides Layout Managers the way Java does to design GUI? I know that it...
89
by: Cuthbert | last post by:
After compiling the source code with gcc v.4.1.1, I got a warning message: "/tmp/ccixzSIL.o: In function 'main';ex.c: (.text+0x9a): warning: the 'gets' function is dangerous and should not be...
14
by: webEater | last post by:
I have a problem, it's not browser specific, and I don't get a solution. I have an (X)HTML document, I show you a part of it: .... <!--<div class="pad">--> <div id="eventImages"><img src=""...
1
by: =?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?= | last post by:
I get the above error in some of the ASP.NET web applications on a server, and I need some help figuring out how to deal with it. This is a rather long post, and I hope I have enough details that...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.