473,416 Members | 1,898 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,416 software developers and data experts.

question about oleDbDataReader HasRows properties



Hi,

I'm using the oleDbDataReader HasRows properties to detect wheter my
table contains a record with the parameter below:
oleDbConnection1.Close();
objreturnst.Parameters["DEPT_CODE"].Value = comboBox2.Text;
objreturnst.Parameters["ST_CODE"].Value = comboBox1.Text;
oleDbConnection1.Open();
OleDbDataReader objreturn = objreturnst.ExecuteReader();
if(objreturn.HasRows) --> this should be false, but it seems it is
always true.. :(
{
objreturn.Read();
retqty = Convert.ToDouble(objreturn["Expr1"]);
}

The SQL statement is:
this.objreturnst.CommandText = "SELECT SUM(TRAN_QTY) AS Expr1 FROM
TRAN2005 WHERE (TRAN_TYPE = \'7\') AND (DEPT_CODE = ?) AND (ST_CODE =
?)";

Since the expression objreturn.HasRows isn't false, so it will generate
the error: Object cannot be cast from DBNull to other types.

I don't know if there's any mistakes in my code, but can someone help
me?

Cheers!

Claudi

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #1
1 2692
> I don't know if there's any mistakes in my code, but can someone help
me?


A better way to tell if any rows are available is to look at the return
value of objreturn.Read().
Also, you should probably cast the return value directly to the expected
type rather than using Convert.ToDouble which is a little less efficient.

using (OleDbDataReader objreturn = objreturnst.ExecuteReader())
{
if (objreturn.Read())
{
if (objreturn[0] is double)
retqty = (double) objreturn[0];
}
}
Nathan
Nov 17 '05 #2

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

Similar topics

1
by: Gary | last post by:
Hi, I have a question is regarding OLEDbDataReader Is there a way to access Data filled to an OLEDBDataReader using field name instead of field position. If not possible using...
0
by: James Hokes | last post by:
Hi All, We're using the 1.1. Framework against SQL Server 2000, and are having a strange issue where we don't get errors back from the stored procedure, i.e. the exception never gets thrown. ...
3
by: Buddy | last post by:
Hello, How do I get the number of row retrieved on a SELECT query when using OleDbDataReader? I am using Framework 1.0.
1
by: charliewest | last post by:
Is there a .Net Compact Framework equivalent in the system.data.sqlserverce namespace of the .Net Framework system.data.sqlclient DataReader object's "Has.Rows" method? For example: ...
4
by: Claudia Fong | last post by:
Hi, I have a form where I need to display the data of a department that stores in a access db. When I first load the form it will call a function name loaddata which will get the first...
14
by: Steve | last post by:
Sorry in advance for my ignorance. Any help would sure be appreciated. I'm writing a fairly simple application with VB.Net and am obviously a bit of a newbie. This application will be used by 1,...
2
by: Miles | last post by:
I have a VB2005 application that has the need to read FoxPro 2.5 DBF/CDX files. I have the code (below) that opens the connection, but there are never any records, nor errors, reported... Can...
11
by: hedbonker | last post by:
I am used to using old school ADO where I might create things like: objConn.Open( sConnectString); objRecordSet.Open ("Select * from users where UID=' + sUserID + "'", objConn); Then I have...
10
by: mg | last post by:
I'm migrating from VB6 and have a question about using 'Using' and the best way to use it. Here is a example of a small bit of code: dbConx("open") Using CN Dim CMD As New OleDbCommand(sSQL,...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
Oralloy
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.