473,398 Members | 2,212 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,398 software developers and data experts.

Selecting fields & Total numbe of records value

hi,
I am selecting fields from three table for manupulating
data and i want to display total number of records
selected. But i am always getting -1 value, eventhough
1000 of records are selected. Below is my code. here
strSelectSQL value is

strSelectSQL = "Select emp.Empno, emp.FirstName,
emp.LastName, emp.DB,
emp.DOJ,emp.Grade,emp.yearofexperience,
emp.basicsalary,emp.hra,emp.lta,
emp.medical,j.JobDescription,dept.Departmentname
From Employee emp with(nolock) inner join Job j with
(nolock) on emp.jobcode = j.jobcode inner join
Department dept with (nolock) on emp.Departmentno =
dept.departmentno "

try
{
EmployeeCommand = new SqlCommand
(strSelectSQL ,EmployeeConnection);
EmployeeConnection.Open();
SqlDataReader myReader;
myReader = EmployeeCommand.ExecuteReader();
lblDispSelectRecord.Text=
myReader.RecordsAffected.ToString();
myReader.Close();
}
catch (SqlException ex)
{
lblErrorMessage.Text = "Error in SQL Execution : " +
ex.ToString();
lblDispSelectRecord.Text = strSelectSQL ;
}
finally
{
EmployeeConnection.Close();
}

I have tried using ExecuteScaler method. But it can be
used only when we are selecting scaler values. I need to
select fields as well as number of records affected. can
anybody explained me

Thanks,
Ramesh
Nov 15 '05 #1
1 2540

Hi Ramesh,

In MSDN, you can see The RecordsAffected property is not set until all rows
are read and you close the SqlDataReader
For more information, you can visit:
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemdatasqlclientsqldatareaderclassrecordsa ffectedtopic.asp

HTH.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| Content-Class: urn:content-classes:message
| From: "Ramesh" <jr*****@hotmail.com>
| Sender: "Ramesh" <jr*****@hotmail.com>
| Subject: Selecting fields & Total numbe of records value
| Date: Sun, 24 Aug 2003 23:50:57 -0700
| Lines: 48
| Message-ID: <06****************************@phx.gbl>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcNq1TyjBDYWE7GzQJqQu0P43meCBw==
| Newsgroups: microsoft.public.dotnet.languages.csharp
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:179082
| NNTP-Posting-Host: TK2MSFTNGXA09 10.40.1.161
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| hi,
| I am selecting fields from three table for manupulating
| data and i want to display total number of records
| selected. But i am always getting -1 value, eventhough
| 1000 of records are selected. Below is my code. here
| strSelectSQL value is
|
| strSelectSQL = "Select emp.Empno, emp.FirstName,
| emp.LastName, emp.DB,
| emp.DOJ,emp.Grade,emp.yearofexperience,
| emp.basicsalary,emp.hra,emp.lta,
| emp.medical,j.JobDescription,dept.Departmentname
| From Employee emp with(nolock) inner join Job j with
| (nolock) on emp.jobcode = j.jobcode inner join
| Department dept with (nolock) on emp.Departmentno =
| dept.departmentno "
|
| try
| {
| EmployeeCommand = new SqlCommand
| (strSelectSQL ,EmployeeConnection);
| EmployeeConnection.Open();
| SqlDataReader myReader;
| myReader = EmployeeCommand.ExecuteReader();
| lblDispSelectRecord.Text=
| myReader.RecordsAffected.ToString();
| myReader.Close();
| }
| catch (SqlException ex)
| {
| lblErrorMessage.Text = "Error in SQL Execution : " +
| ex.ToString();
| lblDispSelectRecord.Text = strSelectSQL ;
| }
| finally
| {
| EmployeeConnection.Close();
| }
|
| I have tried using ExecuteScaler method. But it can be
| used only when we are selecting scaler values. I need to
| select fields as well as number of records affected. can
| anybody explained me
|
| Thanks,
| Ramesh
|
|
|

Nov 15 '05 #2

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

Similar topics

1
by: Rado | last post by:
Hi All, This might quite simple process for some but I am finding it really difficult to do. What is required is not a standard Duplicate query but a variation on it. For example I have...
3
by: CSDunn | last post by:
Hello, I have a situation with MS Access 2000 in which I need to display report data in spreadsheet orientation (much like a datasheet view for a form). If you think of the report in terms of what...
2
by: MLH | last post by:
I have tblMemberLogins with and fields. Any member may appear in the table numerous times. How can I sum up the total time spent logged in by any member in the table, I can extract the records...
6
by: Brian | last post by:
Hello, Basically, I'm running a query on a form's activation, and I'd like to have the results of the query be placed into other fields on the same form automatically. Does anybody know how...
8
by: Maxi | last post by:
There is a lotto system which picks 21 numbers every day out of 80 numbers. I have a table (name:Lotto) with 22 fields (name:Date,P1,P2....P21) Here is the structure and sample data: ...
3
by: Simon | last post by:
Dear reader, I found out a strange behaviour in a query of the type Total (summation query). In case of a normal select query with a criteria setting Is Null for field-A, four (4) records...
2
by: Catch_22 | last post by:
Hi, I have a stored procedure that has to extract the child records for particular parent records. The issue is that in some cases I do not want to extract all the child records only a...
4
by: ajcolburn | last post by:
Hi there, I've been struggling with a query for a while now, and would be grateful if anyone here could help. The database is for an invoicing system, with the following tables & fields involved...
7
by: creative1 | last post by:
Hello everyone. I am experiencing a strange problem that I can't fix on my own. I think I need expert's suggestions for this. The problem is: I want to print account statement (or any other...
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
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
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...

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.