Solved

Delete Row form dataset

Posted on 2008-10-21
3
2,491 Views
Last Modified: 2008-10-22
Hi,
       I want to delete row from dataset or datatable. I just created worktable columns like

        Dim worktable As New DataTable("emrDataTable")
        worktable.columns.Add("Primary Key")
        worktable.Columns.Add("File Name")
        worktable.Columns.Add("APS ID")
        worktable.Columns.Add("Model Name")
        worktable.Columns.Add("Table Name")
        worktable.Columns.Add("Column Name")
        worktable.Columns.Add("Entity Name")
        worktable.Columns.Add("Diagram ID")


            ' (DMK) make a new row
            Dim dRow As DataRow = worktable.NewRow()

            ' (DMK) set the obvious columns
            dRow("Primary Key") = dReader("Primary Key").ToString()
            dRow("File Name") = dReader("File Name").ToString()
            dRow("APS ID") = dReader("APS ID").ToString()
            dRow("Model Name") = dReader("Model Name").ToString()
            dRow("Table Name") = dReader("Table Name").ToString()
            dRow("Column Name") = dReader("Column Name").ToString()
            dRow("Entity Name") = dReader("Entity Name").ToString()
            dRow("Diagram ID") = dReader("Diagram ID").ToString()

Now i want to delete a row from this worktable before dispalying it to the user. I want to delete the row where
Column Name = 'LN_ID' AND Table Name = 'LL_APPLNT_BRWR_CR_SCR' AND Diagram ID = '568' and Primary Key = '0' .

Can anybody provide me the code please. Thanks In advance
0
Comment
Question by:prasadpbr
3 Comments
 
LVL 7

Expert Comment

by:the_bachelor
ID: 22770815
I dont think there is as method of the DataTable Class that will readily delete rows for you. I just took a quick glance at the methods listed in MSDN... Maybe there is a hidden one that I dont know of.

Now there is a Select method though.  You'd for instance say
worktable.Select ( "NOT (Table Name = 'LL_APPLNT_BRWR_CR_SCR' AND Diagram ID = '568')")
for instance.
I will return an array of DataRows that match the criteria.

In essence, What I'm proposing you do is:
1- Use the select Method to filter out the unwanted rows (those that you want to  delete)
2- Then copy or Import the filtrate/ the array of datarows in a New dataTable.
0
 
LVL 13

Expert Comment

by:sm394
ID: 22771377
0
 
LVL 8

Accepted Solution

by:
jorgesv13 earned 125 total points
ID: 22772659
The DataTable.Rows collection has a method to remove rows from it.
What you have to do is:
1. Select the rows that you want to DELETE
2. Iterate on the selected rows, and remove them from the collection
For example:
Dim dRows As DataRow() = worktable.Select("Column Name = 'LN_ID' AND Table Name = 'LL_APPLNT_BRWR_CR_SCR' AND Diagram ID = '568' and Primary Key = '0'")
 

For Each dRow As DataRow In dRows

     worktable.Rows.Remove(dRow)

Next

Open in new window

0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now