|
 |
aspx thread: Record Count.
Message #1 by "Phaneendra-seacom" <phaneendra@s...> on Thu, 31 May 2001 16:05:20 +0530
|
|
Hi all,
I would like to get the record count of a perticular sql.
I dont want to use any stored procedure. I am using C#.
Please help me out.
Regards,
Phaneendra.
Message #2 by "Yackson mata" <yackson.mata@v...> on Thu, 31 May 2001 14:55:52 +0200
|
|
Hi
good to obtain the quantity of registration of a table in SQL statement it
can use and you return it to a control SQL.
this is code source in VS
Dim DS As DataSet
Dim MyConnection As SQLConnection
Dim MyCommand As SQLDataSetCommand
Dim SelectCommand As String =" select count(namefield)as
namevariable from yournametable"
MyConnection = New SQLConnection(conectionDB)
MyCommand = New SQLDataSetCommand(SelectCommand, MyConnection)
DS = new DataSet()
MyCommand.FillDataSet(DS, "yournametable") --> this contained you
counter value
Dropdownlist.DataSource = ds.Tables("yournametable").DefaultView
Dropdownlist.DataBind()
I hope this code helps you
Best regards,Yackson mata
VeneInformática C.A
WWW.VENECA.COM
Message #3 by "Alex Lowe" <alowe@s...> on Thu, 31 May 2001 09:18:09 -0400
|
|
Phaneendra,
This code snippet should do the trick:
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SQL" %>
<script language="C#" runat="server">
void Page_Load(Object Src, EventArgs e)
{
DataSet myDataSet = new DataSet();
String SelectCommand ="Select * from Products";
SQLConnection MyConnection = new SQLConnection("Data Source=test; uid=sa;
pwd=; Initial Catalog=northwind");
SQLDataSetCommand MyCommand = new SQLDataSetCommand(SelectCommand,
MyConnection);
MyCommand.FillDataSet(myDataSet, "Products");
DataView myDataView = myDataSet.Tables["Products"].DefaultView;
int RowCount = myDataView.Table.Rows.Count;
countLabel.Text = RowCount.ToString();
}
</script>
<asp:label id="countLabel" width=100 runat=Server/>
hth,
Alex
http://www.asp-grandrapids.net
webmaster@a...
----- Original Message -----
From: "Phaneendra-seacom" <phaneendra@s...>
To: "ASP+" <aspx@p...>
Sent: Thursday, May 31, 2001 6:35 AM
Subject: [aspx] Record Count.
> Hi all,
> I would like to get the record count of a perticular sql.
> I dont want to use any stored procedure. I am using C#.
>
> Please help me out.
>
> Regards,
> Phaneendra.
Message #4 by "charles baldo" <charlesbaldo@h...> on Thu, 31 May 2001 15:10:57
|
|
Phaneendra,
The method I used was a datareader,I am not sure if it is more efficient
than using a DataSet, I think it is because of the faster readforward
here is the code
'
'Create connection string strConnect here
'
strSQL = "SELECT * FROM Members where MemberID = '" & IDPass & "'"
adoCommand = New ADOCommand( strSQL , strConnection )
adoCommand.ActiveConnection.Open()
adoCommand.Execute(adoReader)
RecordsReturned = 0
While adoReader.Read()
RecordsReturned = RecordsReturned + 1
End While
'
' It works its quick, put it in a function that returns the RecordsReturned
'
I am sure you can modify it for the SQL Server
Chuck
Message #5 by "Samuel Engelman" <samuel_engelman@p...> on Thu, 31 May 2001 10:23:40 -0400
|
|
If all you are trying to get is the count, it isn't necessary to bring
back
all the data. Just use the following query:
Select count(*) from Products
And then access the first column of the first row
|--------+--------------------------------->
| | "Alex Lowe" |
| | <alowe@s...> |
| | |
| | |
| | Thursday May 31, 2001 09:18 AM|
| | Please respond to "ASP+" |
| | |
|--------+--------------------------------->
>--------------------------------------------------------------------
---|
|
|
| To: "ASP+" <aspx@p...
> |
| cc:
|
| Subject: [aspx] Re: Record Count.
|
>--------------------------------------------------------------------
---|
Phaneendra,
This code snippet should do the trick:
<%@ Page Language=3D"C#" %>
<%@ Import Namespace=3D"System.Data" %>
<%@ Import Namespace=3D"System.Data.SQL" %>
<script language=3D"C#" runat=3D"server">
void Page_Load(Object Src, EventArgs e)
{
DataSet myDataSet =3D new DataSet();
String SelectCommand =3D"Select * from Products";
SQLConnection MyConnection =3D new SQLConnection("Data Source=3Dtest;
uid=3Dsa;
pwd=3D; Initial Catalog=3Dnorthwind");
SQLDataSetCommand MyCommand =3D new SQLDataSetCommand(SelectCommand,
MyConnection);
MyCommand.FillDataSet(myDataSet, "Products");
DataView myDataView =3D myDataSet.Tables["Products"].DefaultView;
int RowCount =3D myDataView.Table.Rows.Count;
countLabel.Text =3D RowCount.ToString();
}
</script>
<asp:label id=3D"countLabel" width=3D100 runat=3DServer/>
hth,
Alex
http://www.asp-grandrapids.net
webmaster@a...
----- Original Message -----
From: "Phaneendra-seacom" <phaneendra@s...>
To: "ASP+" <aspx@p...>
Sent: Thursday, May 31, 2001 6:35 AM
Subject: [aspx] Record Count.
> Hi all,
> I would like to get the record count of a perticular sql.
> I dont want to use any stored procedure. I am using C#.
>
> Please help me out.
>
> Regards,
> Phaneendra.
|
|
 |