Solved

Delete Row form dataset

Posted on 2008-10-21
3
2,495 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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)…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

785 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