Get record count from filtered datasourse (not set)

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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;
 
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;
 
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);
}
}
}
}
 
Back
Top