Get record count from filtered datasourse (not set)

G

Guest

What are the steps necessary to get the filtered count from datasource. If i
have to move it into a table just to gat the count i'll do so, but i'm not
sure what the steps are needed to accomplish this.

Thanks
KES
 
M

Mark Rae [MVP]

What are the steps necessary to get the filtered count from datasource. If
i
have to move it into a table just to gat the count i'll do so, but i'm not
sure what the steps are needed to accomplish this.

DataSet MyDS = <fetch DataSet>;
MyDS.Tables[0].DefaultView.RowFilter = "......";
int FilterCount = MyDS.Tables[0].DefaultView.Count;
 
G

Guest

thanks for replying,
I did see this (your answer specific) in another of your postings and it is
what prompted me to repost with the "(not set)". My admitted lack of
knowledge here is how to get my dataSOURCE in to the dataSET. (...<fetch
DataSet>;)

--
thanks (as always)
some day i''m gona pay this forum back for all the help i''m getting
kes


Mark Rae said:
What are the steps necessary to get the filtered count from datasource. If
i
have to move it into a table just to gat the count i'll do so, but i'm not
sure what the steps are needed to accomplish this.

DataSet MyDS = <fetch DataSet>;
MyDS.Tables[0].DefaultView.RowFilter = "......";
int FilterCount = MyDS.Tables[0].DefaultView.Count;
 
M

Mark Rae [MVP]

thanks for replying,
I did see this (your answer specific) in another of your postings and it
is
what prompted me to repost with the "(not set)". My admitted lack of
knowledge here is how to get my dataSOURCE in to the dataSET. (...<fetch
DataSet>;)

You need to know how to create a DataSet?

Firstly, it makes a (slight) difference what RDBMS you're using but, for the
sake of argument, let's say you're using SQL Server...

You'll need to reference the System.Data namespace, and use an appropriate
connection string, something like this:

Data Source=myServerAddress;Initial Catalog=myDataBase;User
Id=myUsername;Password=myPassword;

For more specific examples, see here:
http://www.connectionstrings.com/?carrier=sqlserver2005

string strConnectionString = "<...connection string - see above...>";

using (SqlConnection objSqlConnection = new
SqlConnection(strConnectionString))
{
objSqlConnection.Open();
using (SqlCommand objSqlCommand = new SqlCommand(pstrSQL,
objSqlConnection))
{
using (SqlDataAdapter objDA = new SqlDataAdapter(objSqlCommand))
{
using (DataSet objDataSet = new DataSet())
{
objDA.Fill(objDataSet);
objSqlConnection.Close();
return (objDataSet);
}
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top