Solved

Delete Row form dataset

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

717 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