473,796 Members | 2,501 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:
oleDbConnection 1.Close();
objreturnst.Par ameters["DEPT_CODE"].Value = comboBox2.Text;
objreturnst.Par ameters["ST_CODE"].Value = comboBox1.Text;
oleDbConnection 1.Open();
OleDbDataReader objreturn = objreturnst.Exe cuteReader();
if(objreturn.Ha sRows) --> this should be false, but it seems it is
always true.. :(
{
objreturn.Read( );
retqty = Convert.ToDoubl e(objreturn["Expr1"]);
}

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

Since the expression objreturn.HasRo ws 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 2710
> 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.ToDoubl e which is a little less efficient.

using (OleDbDataReade r objreturn = objreturnst.Exe cuteReader())
{
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
2662
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 OLEDbDataReader, is there any alternative to achieve this?
0
2537
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. The scenario is this: 1.) Set up SqlConnection and SqlCommand 2.) Set SqlDataReader equal to the return value from SqlCommand.ExecuteReader
3
8130
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
4857
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: SqlDataReader rdr = new cmd.ExecuteReader(); if (rdr.HasRows) { // do something
4
3938
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 record from the db and then display for the user: oleDbConnection1.Open();
14
1727
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 or at most 3 people concurrently and I'm using Access 2003 for my data source. We are not dealing with a large amount of data (5 or 6 tables, for a total of maybe 3,000 records - one table having the majority of that). This application is...
2
4016
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 anyone tell me what I'm doing wrong? The ConnectionString resolves to "Provider=VFPOLEDB.1;Data Source=C:\test\REVFILEF.DBF;Mode=Read|Share Deny None;Collating Sequence=MACHINE" Private Function DoDBFProcess(byVal InputFileName as String) As Long
11
1578
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 a recordset collection that I can filter on or step through etc. based on a specific SQL query.
10
1972
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, CN) Dim DR As OleDbDataReader = CMD.ExecuteReader()
0
9683
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9529
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10176
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6792
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5443
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5576
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4119
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3733
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2927
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.