By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,321 Members | 1,875 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,321 IT Pros & Developers. It's quick & easy.

Selecting fields & Total numbe of records value

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a

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 discussion thread is closed

Replies have been disabled for this discussion.