PC Review


Reply
Thread Tools Rate Thread

using the sort and rowFilter from a stored procedure dataset

 
 
Arthur Yousif
Guest
Posts: n/a
 
      25th Aug 2003
Hi,

I'm filling a data set from a stored procedure and then I'd like to do some
more filtering. This additional filtering is not being by the sp so I can
have some control on my side of coding. The code snippet is below and
doesn't work. I'm not sure if I'm using the sort and rowFilter correctly?
I thought if I set these before getting the Table, it would return the data
post sort/filter, but that's not the case, I'm still getting all the
records. Thanks for your help.

SqlConnection sqlConn = new SqlConnection(sConn);
SqlCommand sqlCmd = new SqlCommand("myStoredProcedure", sqlConn);
sqlCmd.CommandType = CommandType.StoredProcedure;
SqlParameter p1;

p1 = new SqlParameter("@parm1", SqlDbType.Int);
p1.Direction = ParameterDirection.Input;
p1.Value = m_contactID;
sqlCmd.Parameters.Add(p1);

sqlCmd.Connection = sqlConn;

SqlDataAdapter sda = new SqlDataAdapter(sqlCmd);
DataSet ds = new DataSet();
sda.Fill(ds);

DataViewManager dvm = ds.DefaultViewManager;
DataViewSettingCollection dvsc = dvm.DataViewSettings;

dvsc[0].RowStateFilter = DataViewRowState.ModifiedCurrent;
dvsc[0].Sort = m_sortField + " " + m_sortValue;
dvsc[0].RowFilter = " statusID = 2 AND fileLoc = '" + folder +
"/'";

DataTable dtSorted = dvsc[0].Table;
DataRowCollection drc = dtSorted.Rows;

int iRows = drc.Count;
for (int r=0; r < iRows; r++)
{
DataRow dr = drc[r];

iColumns = dr.ItemArray.Length;
for (int i=0; i < iColumns; i++)
{
sList += dr.ItemArray.GetValue(i).ToString().Trim();
sList += "~";
}
}

Arthur


 
Reply With Quote
 
 
 
 
Arthur Yousif
Guest
Posts: n/a
 
      25th Aug 2003
I figured this out. I needed to use the Select method on the Table object
like this:


string sSort = m_sortField + " " + m_sortValue;
string sFilter = " statusID = 2 AND fileLoc = '" + folder + "/'";
DataViewManager dvm = ds.DefaultViewManager;
DataViewSettingCollection dvsc = dvm.DataViewSettings;
DataTable dtModified = dvsc[0].Table;
DataRow[] dRows = dtModified.Select(sFilter, sSort);

foreach (DataRow srcRow in dRows)
{
iColumns = srcRow.ItemArray.Length;
for (int i=0; i < iColumns; i++)
{
sList += srcRow[i].ToString().Trim();
sList += "~";
}

}

I hope this helps someone else.

--
Arthur


"Arthur Yousif" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Hi,
>
> I'm filling a data set from a stored procedure and then I'd like to do

some
> more filtering. This additional filtering is not being by the sp so I can
> have some control on my side of coding. The code snippet is below and
> doesn't work. I'm not sure if I'm using the sort and rowFilter correctly?
> I thought if I set these before getting the Table, it would return the

data
> post sort/filter, but that's not the case, I'm still getting all the
> records. Thanks for your help.
>
> SqlConnection sqlConn = new SqlConnection(sConn);
> SqlCommand sqlCmd = new SqlCommand("myStoredProcedure", sqlConn);
> sqlCmd.CommandType = CommandType.StoredProcedure;
> SqlParameter p1;
>
> p1 = new SqlParameter("@parm1", SqlDbType.Int);
> p1.Direction = ParameterDirection.Input;
> p1.Value = m_contactID;
> sqlCmd.Parameters.Add(p1);
>
> sqlCmd.Connection = sqlConn;
>
> SqlDataAdapter sda = new SqlDataAdapter(sqlCmd);
> DataSet ds = new DataSet();
> sda.Fill(ds);
>
> DataViewManager dvm = ds.DefaultViewManager;
> DataViewSettingCollection dvsc = dvm.DataViewSettings;
>
> dvsc[0].RowStateFilter = DataViewRowState.ModifiedCurrent;
> dvsc[0].Sort = m_sortField + " " + m_sortValue;
> dvsc[0].RowFilter = " statusID = 2 AND fileLoc = '" + folder +
> "/'";
>
> DataTable dtSorted = dvsc[0].Table;
> DataRowCollection drc = dtSorted.Rows;
>
> int iRows = drc.Count;
> for (int r=0; r < iRows; r++)
> {
> DataRow dr = drc[r];
>
> iColumns = dr.ItemArray.Length;
> for (int i=0; i < iColumns; i++)
> {
> sList += dr.ItemArray.GetValue(i).ToString().Trim();
> sList += "~";
> }
> }
>
> Arthur
>
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataSet from Stored Procedure Microsoft ADO .NET 5 18th Jan 2008 12:17 PM
Re: Typed DataSet and Stored Procedure Mythran Microsoft ADO .NET 0 25th Aug 2004 07:10 PM
returning dataset from stored procedure Mike P Microsoft C# .NET 3 5th Aug 2004 01:13 PM
stored procedure + dataset Alejandro Becker Microsoft ADO .NET 5 18th Oct 2003 01:51 AM
Typed dataset via stored procedure. Jim Boyd Microsoft ADO .NET 1 26th Aug 2003 10:55 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:58 PM.