我需要解析一个Command.CommandText
.
我不想运行查询。我只想看看如果执行命令,查询是否会成功。
说我有;"SELECT * FROM SomeTable WHERE (1=1)"
该字符串将会成功。
but,
"SELECT * FROM SomeTable WHERE (1=1"
不会成功。
现在我的问题。我会怎样Parse
这个字符串c#
?
如果您只是想验证语法。您可以使用Microsoft.Data.Schema.ScriptDom http://blogs.msdn.com/b/gertd/archive/2008/08/21/getting-to-the-crown-jewels.aspx为了这。
using Microsoft.Data.Schema.ScriptDom;
using Microsoft.Data.Schema.ScriptDom.Sql;
.....
string sql = "SELECT * FROM SomeTable WHERE (1=1";
var p = new TSql100Parser(true);
IList<ParseError> errors;
p.Parse(new StringReader(sql), out errors);
if (errors.Count == 0)
Console.Write("No Errors");
else
foreach (ParseError parseError in errors)
Console.Write(parseError.Message);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)