I am using a datareader (dr1) to read through rows returned from a query. I
am getting the error: "No data exists for the row/column." at the "If
IsDbNull..." in the code below. The field "Photo1" does exist and in some
rows it is null, in others it may be an empty string and in others it may
have a file name. I don't understand exactly what the system is complaining
about here?
Wayne
=========== code ============
If IsDBNull(dr1.Item("Photo2")) Then
txtPhoto2.Text = ""
Else
txtPhoto2.Text = dr1.Item("Photo2")
End If 10 1296
Did you do a dr1.Read() first?
--
I hope this helps,
Steve C. Orr, MCSD, MVP http://SteveOrr.net
"Wayne Wengert" <wa***************@wengert.com> wrote in message
news:eh**************@tk2msftngp13.phx.gbl... I am using a datareader (dr1) to read through rows returned from a query. I am getting the error: "No data exists for the row/column." at the "If IsDbNull..." in the code below. The field "Photo1" does exist and in some rows it is null, in others it may be an empty string and in others it may have a file name. I don't understand exactly what the system is complaining about here?
Wayne =========== code ============ If IsDBNull(dr1.Item("Photo2")) Then
txtPhoto2.Text = ""
Else
txtPhoto2.Text = dr1.Item("Photo2")
End If
Where's the complete code, are you doing a while dr1.Read() before you check
for null?
While dr1.Read()
If IsDBNull(dr1.Item("Photo2")) Then
End
--
Manohar Kamath
Editor, .netWire www.dotnetwire.com
"Wayne Wengert" <wa***************@wengert.com> wrote in message
news:eh**************@tk2msftngp13.phx.gbl... I am using a datareader (dr1) to read through rows returned from a query.
I am getting the error: "No data exists for the row/column." at the "If IsDbNull..." in the code below. The field "Photo1" does exist and in some rows it is null, in others it may be an empty string and in others it may have a file name. I don't understand exactly what the system is
complaining about here?
Wayne =========== code ============ If IsDBNull(dr1.Item("Photo2")) Then
txtPhoto2.Text = ""
Else
txtPhoto2.Text = dr1.Item("Photo2")
End If
If a column in a row doesn't exist, then IsDbNull will not be able to
evaluate the contents of the cell because there aren't any contents of the
cell. If the field doesn't exist you need to catch the
IndexOutOfRangeException exception that it will throw. Remember, a null
value in a database is a special value being passed from the db and not the
same as a null used in typical programming languages.
Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage
"Wayne Wengert" <wa***************@wengert.com> wrote in message
news:eh**************@tk2msftngp13.phx.gbl... I am using a datareader (dr1) to read through rows returned from a query. I am getting the error: "No data exists for the row/column." at the "If IsDbNull..." in the code below. The field "Photo1" does exist and in some rows it is null, in others it may be an empty string and in others it may have a file name. I don't understand exactly what the system is complaining about here?
Wayne =========== code ============ If IsDBNull(dr1.Item("Photo2")) Then
txtPhoto2.Text = ""
Else
txtPhoto2.Text = dr1.Item("Photo2")
End If
Yes, that code is in a read loop
Wayne
"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message
news:OW**************@TK2MSFTNGP09.phx.gbl... Did you do a dr1.Read() first?
-- I hope this helps, Steve C. Orr, MCSD, MVP http://SteveOrr.net
"Wayne Wengert" <wa***************@wengert.com> wrote in message news:eh**************@tk2msftngp13.phx.gbl...I am using a datareader (dr1) to read through rows returned from a query.
I am getting the error: "No data exists for the row/column." at the "If IsDbNull..." in the code below. The field "Photo1" does exist and in
some rows it is null, in others it may be an empty string and in others it
may have a file name. I don't understand exactly what the system is complaining about here?
Wayne =========== code ============ If IsDBNull(dr1.Item("Photo2")) Then
txtPhoto2.Text = ""
Else
txtPhoto2.Text = dr1.Item("Photo2")
End If
The "complete code" is over 600 lines with may subs and functions being
called. I am getting suspicious that I may have a call to a sub that closes
the reader - I'll put in some brakes to see if I can isolate it.
Wayne
"Manohar Kamath" <mk*****@TAKETHISOUTkamath.com> wrote in message
news:uv**************@TK2MSFTNGP15.phx.gbl... Where's the complete code, are you doing a while dr1.Read() before you
check for null?
While dr1.Read() If IsDBNull(dr1.Item("Photo2")) Then End
-- Manohar Kamath Editor, .netWire www.dotnetwire.com
"Wayne Wengert" <wa***************@wengert.com> wrote in message news:eh**************@tk2msftngp13.phx.gbl... I am using a datareader (dr1) to read through rows returned from a
query. I am getting the error: "No data exists for the row/column." at the "If IsDbNull..." in the code below. The field "Photo1" does exist and in
some rows it is null, in others it may be an empty string and in others it
may have a file name. I don't understand exactly what the system is complaining about here?
Wayne =========== code ============ If IsDBNull(dr1.Item("Photo2")) Then
txtPhoto2.Text = ""
Else
txtPhoto2.Text = dr1.Item("Photo2")
End If
I'm using the same code in my software and it works like a champ.
This leads me to believe that maybe you don't actually have a "Photo2"
column in your result set as you think you do.
Try this experiment, use the numeric index of the data column instead of the
column name, such as this:
If IsDBNull(dr1.Item(0)) Then...
--
I hope this helps,
Steve C. Orr, MCSD, MVP http://SteveOrr.net
"Wayne Wengert" <wa***************@wengert.com> wrote in message
news:un**************@TK2MSFTNGP14.phx.gbl... Yes, that code is in a read loop
Wayne
"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message news:OW**************@TK2MSFTNGP09.phx.gbl... Did you do a dr1.Read() first?
-- I hope this helps, Steve C. Orr, MCSD, MVP http://SteveOrr.net
"Wayne Wengert" <wa***************@wengert.com> wrote in message news:eh**************@tk2msftngp13.phx.gbl... >I am using a datareader (dr1) to read through rows returned from a >query. I > am getting the error: "No data exists for the row/column." at the "If > IsDbNull..." in the code below. The field "Photo1" does exist and in some > rows it is null, in others it may be an empty string and in others it may > have a file name. I don't understand exactly what the system is > complaining > about here? > > Wayne > > > > =========== code ============ > If IsDBNull(dr1.Item("Photo2")) Then > > txtPhoto2.Text = "" > > Else > > txtPhoto2.Text = dr1.Item("Photo2") > > End If > >
I had a sub that closed the reader under certain conditions. That was
causing the error. Fixed the logic and now it is working.
I appreciate the suggestions.
Wayne
"Wayne Wengert" <wa***************@wengert.com> wrote in message
news:eh**************@tk2msftngp13.phx.gbl... I am using a datareader (dr1) to read through rows returned from a query.
I am getting the error: "No data exists for the row/column." at the "If IsDbNull..." in the code below. The field "Photo1" does exist and in some rows it is null, in others it may be an empty string and in others it may have a file name. I don't understand exactly what the system is
complaining about here?
Wayne =========== code ============ If IsDBNull(dr1.Item("Photo2")) Then
txtPhoto2.Text = ""
Else
txtPhoto2.Text = dr1.Item("Photo2")
End If
Yeah working with Reader is a pain the Ass sometimes!!
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Being an old fart with limited skills doesn't help either <smirk!>
Wayne
"Patrick Olurotimi Ige" <ig*@iprimus.com.au> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl... Yeah working with Reader is a pain the Ass sometimes!! *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
Can u please explain what a sub means and how the sub was responsible
for the error. I am in a similar situation and not able to understand
how the exception is thrown.
George
*** Sent via Developersdex http://www.developersdex.com *** This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Tobias Langner |
last post by:
compiling this line:
SmartPtr<LongWrapper, RefCount> p1=SmartPtr<LongWrapper, RefCount>(new
LongWrapper(1));
with SmartPtr being:
template <class T, template <class> class OwnershipPolicy>...
|
by: Sam |
last post by:
Hi I'm learning to code with C++ and wrote some very simple code. I
think it's consistent with every rule but always got compiling errors
that I don't understand.
The code include 5 files as...
|
by: Jace Benson |
last post by:
Ok I have read alot of things on zend.com, php.net and other sites went
to the wikibooks to try to understand how to use a class. I have this
project I want to do that I am sure would work great...
|
by: Joshua Moore |
last post by:
/* Hi, I was hoping someone could help me with this problem. I did my
work and worked my way through the usual compiler messages, but I have
run against some problem I can't identify. The compiler...
|
by: Jo |
last post by:
class A {
public:
char text_a;
A() { *text_a=0; }
~A() {}
};
//-----------------------------------------------------------------------------
|
by: Jonathan Wood |
last post by:
The following code raises the error "Specified cast is not valid."
MembershipUser user = Membership.GetUser(userId);
DataSet ds = DataLayer.ExecQueryData("SELECT * FROM mc_Clients WHERE...
|
by: Ben Thomas |
last post by:
Hello,
I have the following code which I don't understand why it works :
#include <iostream>
using namespace std;
void DontWork (unsigned int& i) {
cout << i << endl;
}
|
by: Stef Mientki |
last post by:
hello,
I've syntax error which I totally don't understand:
########## mainfile :
import test_upframe2
if __name__ == '__main__':
var1 = 33
code = 'print var1 + 3 \n'
|
by: Stef Mientki |
last post by:
Terry Reedy wrote:
sorry, don't know how this happened, as I always copy/paste ?
AFAIK locals() == sys._getframe(0).f_locals
AFAIK, again one level up
weird, I use it in 2.5 and if I remember...
|
by: Thierry |
last post by:
Hello fellow pythonists,
I'm a relatively new python developer, and I try to adjust my
understanding about "how things works" to python, but I have hit a
block, that I cannot understand.
I...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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...
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |