|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Deleting from a dataviewOk...
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. Hi Stephen,
DataView is just a view over a DataTable thus deleting records from DataView will delete them for good :-) -- Show quoteHide quoteMiha 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. 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. > > > 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. Hi Stephen,
You don't need AcceptChanges normally. Why are you calling it? -- Show quoteHide quoteMiha 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: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.
Other interesting topics
disconnected typed dataset
DataAdapter Update Does Nothing ADO error "There is already an open DataReader associated with this Connection" SQLHelper.ExecuteReader - Connection Close Can't Read Excel File (OleDb) w/ ASP.NET Impersonation BLOB fields and Microsoft Access Filling multiple tables Oracle Data Providers (Connection Pooling & Transactions) Importing Excel data to Access Simple asynchronous method |
|||||||||||||||||||||||