Link to home
Start Free TrialLog in
Avatar of prasadpbr
prasadpbr

asked on

Delete Row form dataset

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
Avatar of the_bachelor
the_bachelor

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.
ASKER CERTIFIED SOLUTION
Avatar of Jorge Sanchez
Jorge Sanchez
Flag of Ecuador image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial