Datatable select & problem with Apostrophe

Hi All,

I am trying to select some row from a datatable & store in Array of datarows where the datatable column contains a particular string. I am using the following code for this:
Datarow = Datatable.Select(“Columnname = '”+Stringinput+"’")

This code is working fine until the Stringinput has some Apostrophe in it. For example if The stringinput is like : " This is John’s pen" then it is throwing error Assign: Syntax error: Missing operand after ‘s’ operator.

Please suggest me what can be an workaround here.

1 Like

Hey @Paramita.Pradhan

Use this:-

Datarow[ ] Results = Datatable.Select(string.Format("Columnname ='{0}'",Stringinput.ToString().Replace("'","''"))))



Thanks a lot. It is working perfectly

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.