Showing posts with label sqldatasourcemode. Show all posts
Showing posts with label sqldatasourcemode. Show all posts

Tuesday, March 27, 2012

Access DB via SqlDataSource....need result in DataSet

Hi all...I've set the DataSourceMode = SqlDataSourceMode.DataSet, and did a .Type return and found that it is actually returning a DataView. A component I am trying to avoid rewriting...requires a dataset that loops through the table, does some cool formatting to a datagrid and then rebinds.

Here's the code that I'm trying to send the dataset to...maybe there's just a couple of changes that could make it work with a DataView?

int i = 0;
string prevsub = "";
while (i <= ds.Tables[0].Rows.Count - 1)
{
DataRow dr = ds.Tables[0].Rows[i];
string sub = dr["SubHeading"].ToString();
if (sub != prevsub)
{
prevsub = sub;
DataRow newrow = ds.Tables[0].NewRow();
newrow["Title"] = "SubHeading";
newrow[columnName] = dr[columnName];
ds.Tables[0].Rows.InsertAt(newrow, i);
i++;
}
i++;
}

DataView is very close to the dataset object in this context.

my test code:

DataView dv = (DataView) SqlDataSource1.Select(DataSourceSelectArguments.Empty);


int i = 0;
string prevsub = "";
while (i <= dv.Table.Rows.Count - 1)
{
DataRow dr = dv.Table.Rows[i];
string sub = dr["mycol1"].ToString();
if (sub != prevsub)
{
prevsub = sub;
DataRow newrow = dv.Table.NewRow();
newrow["mycol1"] = "SubHeading";
newrow["mycol2"] = dr["mycol2"];
dv.Table.Rows.InsertAt(newrow, i);
i++;
}
i++;
}

Hope this helps.

|||Hi there. Thanks so much limno! That did the trick. I was hoping that the dv would be similar enough to be able to use this code. Great to know and use for the future. Much appreciated!