Solved

Delete Row form dataset

Posted on 2008-10-21
3
2,497 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display

733 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