我如何在C#中dataTable.Select()查询剥离单引号? [英] How can I strip a single quote from a dataTable.Select( ) query in C#?

查看:840
本文介绍了我如何在C#中dataTable.Select()查询剥离单引号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有经销商的名单,我正在寻找他们在我的数据表 - 问题是,一些chucklehead已被命名为年轻的---这将导致一个错误

So I have a list of dealers names and I am searching them in my datatable -- problem is, some chucklehead HAS to be named 'Young's' --- this causes an error.

drs = dtDealers.Select("DealerName = '" + dealerName + "'");



于是,我就替换字符串(虽然它没有为我工作 - 也许我不知道如何使用替换...)

So I tried to replace the string (although it didnt work for me - maybe I dont know how to use replace...)

 DataRow[] drs;
                if (dealerName.Contains("'"))
                {
                    string dealerSearch = dealerName;
                    dealerSearch = dealerSearch.Replace("'", "\'");
                    drs = dtDealers.Select("DealerName = '" + dealerSearch + "'");
                }
                else
                {
                    drs = dtDealers.Select("DealerName = '" + dealerName + "'");
                }



任何人有任何好的想法?

Anyone have any good ideas?

谢谢!
托德

Thanks! Todd

推荐答案

您可以使用@操作称为逐字运营商,这意味着在拉丁语文字。它不会做字符串中的人物,否则将意味着什么的任何解释。

You can use the @ operator called the verbatim operator which means literal in latin. It will not do any interpretation of the characters within the string that would otherwise mean something.

这篇关于我如何在C#中dataTable.Select()查询剥离单引号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆