Expression DataTable Unable to interpret token '!'

I have the following code:

//myDataTable has the following collumns: UserName, Birthday and email.
string name = "eric!";
string expression = "UserName = " + name;
DataRow[] result = myDataTable.Select(expression);

I want to select all rows with the name "eric!".
"!" gives me the following error:

Unable to interpret token "!" .

How can I select all rows with such tokens?
(I really need the expression “!” In the expression since I am extracting usernames from the .sql file)

+3
source share
2 answers

You must use namebetween ''. How;

string name = "'eric!'";

DataTable.Select , ! , DataColumn.Expression .

;

. .

+4

(' ')

string name = "eric!";
string expression = "UserName = '" + name+'";
DataRow[] result = myDataTable.Select(expression);

!, ! , .

+2

All Articles