logo
down
shadow

how to delete a row if datatable has any special characters in column?


how to delete a row if datatable has any special characters in column?

By : user2953145
Date : November 20 2020, 01:01 AM
With these it helps Here is an example of what you can do based on my understanding ... your variable names and process to load the data will be different. You maybe able to acheave the same result with less code using Regex and Linq.
code :
        //array of bad chars you don't want in your data - Must be of char type 
        char [] chars=new char[] { '$','-','#'}; //Add all bad chars here...
        //define and load the datatable
        DataTable dt = new DataTable("test");
        DataColumn c0 = new DataColumn("Contacts");
        dt.Columns.Add(c0);
        DataColumn c1 = new DataColumn("Serial");
        dt.Columns.Add("c1");
        DataColumn c3 = new DataColumn("Notes");
        dt.Columns.Add(c3);
        //load some data
        dt.Rows.Add(new object[]  {"a","1234$542341","no$$tes1"} );
        dt.Rows.Add(new object[]  {"b#","12342241","notes2"} );
        dt.Rows.Add(new object[] { "c?", "-421341", "notes3" });
        dt.Rows.Add(new object[] { "DD", "12345", "notes3" });

        //loop through each cell, when a cell contains bad data,
        //remove the entire row and skip remainig cells 

        if (dt == null) return;
        Console.WriteLine("Rows before:" + dt.Rows.Count.ToString());
        if (dt.Rows.Count == 0) return;

        int c = dt.Rows.Count;

        for (int r = c-1; r > -1; r--)
        {
            Console.WriteLine("***Row: "); 

            foreach (var item in dt.Rows[r].ItemArray) // Loop over the items.
            {
                if (item.ToString().IndexOfAny(chars) > -1)
                {
                    Console.Write("Bad Content: ");
                    Console.WriteLine(item);
                    dt.Rows[r].Delete(); //remove row
                    break;//skip remaining cells
                }
            }
        }
        dt.AcceptChanges();
        Console.WriteLine("Rows after:"+dt.Rows.Count.ToString());
        Console.Read();


Share : facebook icon twitter icon
How to access an column with special characters using DataTable.Select()?

How to access an column with special characters using DataTable.Select()?


By : shawn cena
Date : March 29 2020, 07:55 AM
This might help you I have a DataTable with column such as # of Students and would like to sort by this in descending order. Here is my code: , You should use [] brackets, like this :
code :
var rows = dt.Select("","[# of Students] desc");
Delete numbers, special characters and text containing special characters in notepad++

Delete numbers, special characters and text containing special characters in notepad++


By : nobrain
Date : March 29 2020, 07:55 AM
seems to work fine With the help of regular expressions it's easy. Go to Search > Replace menu (shortcut CTRL+H) and do the following:
code :
[0-9\{\}\[\]]|[a-zA-Z]+\#[a-zA-Z\#]+
[leave empty!]
C# Datatable Escape Special Characters

C# Datatable Escape Special Characters


By : Sagittarius
Date : March 29 2020, 07:55 AM
this one helps. I have a a datatable which I need to loop through and remove any special characters such as ' and & and also any empty strings. , Just use a foreach-loop and modify the DataRows:
code :
foreach(DataRow row in dataTable.Rows)
{
    string addr1 = row.Field<string>("Address1");
    addr1 = addr1.Replace("'", "").Replace("&", "").Replace(" ", "");
    row.SetField("Address1", addr1);

    string addr2 = row.Field<string>("Address2");
    addr2 = addr2.Replace("'", "").Replace("&", "").Replace(" ", "");
    row.SetField("Address2", addr2);

    string addr3 = row.Field<string>("Address3");
    addr3 = addr3.Replace("'", "").Replace("&", "").Replace(" ", "");
    row.SetField("Address3", addr3);

    string lat = row.Field<string>("lat");
    lat = lat.Replace("0", "");
    row.SetField("lat", lat);

    string lng = row.Field<string>("lng");
    lng = lng.Replace("0", "");
    row.SetField("lng", lng);
}
// ...
int lat = row.Field<int>("lat");
int? newLat = null;
if(lat != 0) newLat = lat;
row.SetField("lat", newLat);

int lng = row.Field<int>("lng");
int? newLng = null;
if (lng != 0) newLng = lat;
row.SetField("lng", newLng);
// ...
Sql - delete all rows of a column containing special characters(not alphanumeric)

Sql - delete all rows of a column containing special characters(not alphanumeric)


By : raveena
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further Codecaster gave you the path to the solution. Decompose to get it.
You have this :
code :
SELECT * FROM table WHERE column REGEXP '^[A-Za-z0-9]+$'
DELETE FROM table 
WHERE ID NOT IN
(
    SELECT ID FROM table WHERE column REGEXP '^[A-Za-z0-9]+$'
)
DELETE FROM table WHERE column NOT REGEXP '^[A-Za-z0-9]+$'
Special characters in DataTable column names in JQuery/Javascript

Special characters in DataTable column names in JQuery/Javascript


By : kremo
Date : March 29 2020, 07:55 AM
Does that help If you are using the data option as a string, the brackets get interpreted as array notation. The datatables documentation states the following:
code :
cols.push({
    data: function(row) {
      return row["[bla]"];
    },
    title:"[bla]",
    render: $.fn.dataTable.render.number(",",".",3)
});
cols.push({
data: function(row, type, set, meta) {
  return row[theColumns[meta.col].theColumnName];
},
title: theColumns[i].theColumnName,
render: $.fn.dataTable.render.number(",",".",3)
});
Related Posts Related Posts :
  • Stop Continuation Task upon exception thrown from parent task
  • Is there a way to make msbuild write error output to stderr?
  • Unit testing: TDD with POCO Objects with navigation properties (relationship fixup)
  • GridSplitter disables my RowDefinition style
  • Memory leak only in Release mode
  • how to read specified string from url
  • how to store html code EMail template in a string variable or textbox c#
  • Set Selected Date to TimePicker wpf (TimePickers inside DataTemplate)
  • How to draw line in Silverlight Specifying Height?
  • Stored procedure executes but does not update data
  • ASP.NET ListBox Trouble
  • Why does C# also not allow empty conditions in while loops?
  • Unable to get a block of code into my regex match groups
  • What is difference between dbcontext.Add and dbcontext.AddObject
  • How do I update the file version number of C# DLL without recompiling?
  • Value for html control always null
  • HttpClient hangs when timeout is setting (Windows Phone)
  • Handle Multiple Form tag in asp.net page?
  • create word document with html content in c#
  • Confusion about Find And Replace
  • Format sms messages in Clickatell
  • Automated Function Overload
  • String to date in MS Access SQL statement gives type mismatch error
  • ShowDialog exiting on certain events
  • Is there a try Convert.ToInt32... avoiding exceptions
  • How to move wpf application into minimize tray at Window Start-up C#?
  • How to change display format of long variable?
  • How to use Addfields in MongoDB C# Aggregation Pipeline
  • MsTest TestCleanup method not called when an unhandled exception is thrown
  • missing last data when exporting gridview to excel
  • How to add array of objects to List in c#
  • Lambda Expression to order (sort) my list collection
  • Library for displaying music notation
  • How to compare two dictionaries in c# and get the output as True and False after validation
  • specify fields to be serialized with JSON
  • How do you obtain the content of a specific node using XmlDocument in C#?
  • How to ignore the first line in a csv file when you read the csv file in C#
  • c# - Problem calling public void from class
  • How to tell a class which objects it should create? Type vs. object confusion :(
  • Save CheckBox state to xml
  • WIX CAQuietExec NETSH Command Fails
  • Issues sending http put request every 60 seconds to RoR app
  • ConfigurationManager.ConnectionStrings.ConnectionString Issue
  • Real size WPF controls for printing
  • How to cancel properly?
  • C# String multiplication error
  • Using Solrnet and Assigning Attributes with Entity Framework Generated POCOs
  • Regex pattern for single backslash
  • TextBox: insert spaces for credit card number?
  • C# DLL loaded for exe-application is not found when launching similar DLL by rundll32.exe
  • Debug a Windows Service with WCF library
  • Open a file from an external assembly?
  • Servicestack RegistrationFeature Unable to bind request
  • Index was outside the bounds of the array confusion
  • Error in Xml to List code. The ':' character, hexadecimal value 0x3A, cannot be included in a name
  • I am trying to do a while loop with a string conditional statement in C#
  • C# 'Cannot access a disposed object. Object name: 'SslStream'.'
  • How to make Gecko use seperate CookieContainer per instance?
  • C# Advanced form "please wait"
  • Send and Receive data C# using network stream
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org