Search code examples
c#.netasp.netnulloledb

Handle NUL (\0) in C#


I'm retrieving data from a .xls file using oledb and assigning it to a string variable Values using below line:

values += "'" + System.Security.SecurityElement.Escape(row[i].ToString()) + "',";

It woks fine for best case, but if any cell contains the value \0, thereafter values variable will not update with further values. How can I get rid from it?


Solution

  • Well you can get rid of null characters from a string really easily:

    text = text.Replace("\0", "");
    

    ... but is there any way you can use a prepared statement instead of putting the values directly into the SQL? Or does OLEDB not support that?