Selecting fields & Total numbe of records value

  • Thread starter Thread starter Ramesh
  • Start date Start date
R

Ramesh

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
 
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/default.asp?url=/library/en-us/cpref/html/
frlrfsystemdatasqlclientsqldatareaderclassrecordsaffectedtopic.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" <[email protected]>
| Sender: "Ramesh" <[email protected]>
| Subject: Selecting fields & Total numbe of records value
| Date: Sun, 24 Aug 2003 23:50:57 -0700
| Lines: 48
| Message-ID: <[email protected]>
| 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
|
|
|
 
Back
Top