Note that there are some explanatory texts on larger screens.

plurals
  1. PORemove Single Quotes From All Cells in a DataTable - Creating New Table - Using LINQ in Vb.Net
    primarykey
    data
    text
    <p>I have a table with many values inside of it that might have single quotes around them. I need to create a duplicate table without those single quotes. I can't modify the original table as I need to use it, 'as-is' later.</p> <p>I've done this with a table.Clone and using a foreach to loop through the rows and columns removing single quotes as I need and then putting that new row into the new table. It works and it's straight forward.....but</p> <p>I'd like to do the same thing using LINQ. This was my attempt....</p> <pre><code> Dim myResults = From myRow In dtTable _ From myItem In myRow.ItemArray _ Where TypeOf myItem Is String AndAlso _ myItem.ToString.StartsWith("'"c) AndAlso _ myItem.ToString.EndsWith("'"c) </code></pre> <p>As you can see - I didn't get very far. I had trouble finding examples that weren't looking at a specific column in the DataRow. It looks like my code does pull back all the matching results - but I'm at a lose for how I can create a duplicate table/modify the values?</p> <p>EDIT - I've started a bounty for this in the hopes that someone can provide a solution. The only requirement is to not using a For Each; as I already know how to do that. I've gotten closer - but I still can't seem to create a new row or a new table.</p> <p>My new approach hits a dead-end when I try to do this:</p> <pre><code>Dim MyNewRow As New Data.DataRow With {.ItemArray = myRemovedQuotes.ToArray} </code></pre> <p>The Error message I get says, "Error 1 'System.Data.DataRow.Protected Friend Sub New(builder As System.Data.DataRowBuilder)' is not accessible in this context because it is 'Protected Friend'."</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload