Home All Groups Group Topic Archive Search About

Deleting from a dataview

Author
13 Apr 2005 3:37 PM
Stephen Zachmann
Ok...
I have a dataset, which I use to populate a dataview
I filter the dataview based on user criteria
The dataview is bound to a datagrid
I want to delete the filtered set of records from the dataset not just the
dataview.
I have a feeling this is simple and I'm just missing something but I feel
lost.  Any help would be great.  Thanks in advance.
Author
13 Apr 2005 4:42 PM
Miha Markic [MVP C#]
Hi Stephen,

DataView is just a view over a DataTable thus deleting records from DataView
will delete them for good :-)

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
www.rthand.com
SLODUG - Slovene Developer Users Group www.codezone-si.info

Show quoteHide quote
"Stephen Zachmann" <StephenZachm***@discussions.microsoft.com> wrote in
message news:E925E312-7757-438E-8488-ADB958CD3FCA@microsoft.com...
> Ok...
> I have a dataset, which I use to populate a dataview
> I filter the dataview based on user criteria
> The dataview is bound to a datagrid
> I want to delete the filtered set of records from the dataset not just the
> dataview.
> I have a feeling this is simple and I'm just missing something but I feel
> lost.  Any help would be great.  Thanks in advance.
Are all your drivers up to date? click for free checkup

Author
13 Apr 2005 5:00 PM
John Papa
Tis true. You can test this using the following code sample, which deletes a
single row from a DataView and then shows the before and after rowstaste of
the DataSet. Notice the DataSet still contains the deleted row, but tis
rowstate is changed to "deleted".

DataSet ds = new DataSet("TestDS");
string sConnString = "Server=localhost\\sql;Database=Northwind;Integrated
Security=True";
string sSql = "SELECT CategoryID, CategoryName FROM Categories ORDER BY
CategoryName";
using (SqlConnection cn = new SqlConnection(sConnString))
using (SqlCommand cmd = new SqlCommand(sSql, cn))
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
    da.Fill(ds, "Categories");
DataView dv = new DataView(ds.Tables["Categories"]);
System.Diagnostics.Debug.WriteLine("# of Rows " +
ds.Tables["Categories"].Rows.Count.ToString() + Environment.NewLine);
System.Diagnostics.Debug.WriteLine("0th Row's RowState " +
ds.Tables["Categories"].Rows[0].RowState.ToString() + Environment.NewLine);
dv.Delete(0);
System.Diagnostics.Debug.WriteLine("# of Rows " +
ds.Tables["Categories"].Rows.Count.ToString() + Environment.NewLine);
System.Diagnostics.Debug.WriteLine("0th Row's RowState " +
ds.Tables["Categories"].Rows[0].RowState.ToString() + Environment.NewLine);



// John Papa
// http://codebetter.com/blogs/john.papa



Show quoteHide quote
"Miha Markic [MVP C#]" wrote:

> Hi Stephen,
>
> DataView is just a view over a DataTable thus deleting records from DataView
> will delete them for good :-)
>
> --
> Miha Markic [MVP C#] - RightHand .NET consulting & development
> www.rthand.com
> SLODUG - Slovene Developer Users Group www.codezone-si.info
>
> "Stephen Zachmann" <StephenZachm***@discussions.microsoft.com> wrote in
> message news:E925E312-7757-438E-8488-ADB958CD3FCA@microsoft.com...
> > Ok...
> > I have a dataset, which I use to populate a dataview
> > I filter the dataview based on user criteria
> > The dataview is bound to a datagrid
> > I want to delete the filtered set of records from the dataset not just the
> > dataview.
> > I have a feeling this is simple and I'm just missing something but I feel
> > lost.  Any help would be great.  Thanks in advance.
>
>
>
Author
13 Apr 2005 7:09 PM
Stephen Zachmann
Thanks a ton guys.  I was forgetting to put the ds.acceptchanges() after my
dataview deletes.  Anyway, thanks for your help.

Show quoteHide quote
"Stephen Zachmann" wrote:

> Ok...
> I have a dataset, which I use to populate a dataview
> I filter the dataview based on user criteria
> The dataview is bound to a datagrid
> I want to delete the filtered set of records from the dataset not just the
> dataview.
> I have a feeling this is simple and I'm just missing something but I feel
> lost.  Any help would be great.  Thanks in advance.
Author
13 Apr 2005 7:51 PM
Miha Markic [MVP C#]
Hi Stephen,

You don't need AcceptChanges normally.
Why are you calling it?

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
www.rthand.com
SLODUG - Slovene Developer Users Group www.codezone-si.info

Show quoteHide quote
"Stephen Zachmann" <StephenZachm***@discussions.microsoft.com> wrote in
message news:3F662DC7-5D5E-45F5-8F67-036051EBD35C@microsoft.com...
> Thanks a ton guys.  I was forgetting to put the ds.acceptchanges() after
> my
> dataview deletes.  Anyway, thanks for your help.
>
> "Stephen Zachmann" wrote:
>
>> Ok...
>> I have a dataset, which I use to populate a dataview
>> I filter the dataview based on user criteria
>> The dataview is bound to a datagrid
>> I want to delete the filtered set of records from the dataset not just
>> the
>> dataview.
>> I have a feeling this is simple and I'm just missing something but I feel
>> lost.  Any help would be great.  Thanks in advance.

Bookmark and Share