<bdo id='95qSI'></bdo><ul id='95qSI'></ul>

    <small id='95qSI'></small><noframes id='95qSI'>

    <i id='95qSI'><tr id='95qSI'><dt id='95qSI'><q id='95qSI'><span id='95qSI'><b id='95qSI'><form id='95qSI'><ins id='95qSI'></ins><ul id='95qSI'></ul><sub id='95qSI'></sub></form><legend id='95qSI'></legend><bdo id='95qSI'><pre id='95qSI'><center id='95qSI'></center></pre></bdo></b><th id='95qSI'></th></span></q></dt></tr></i><div id='95qSI'><tfoot id='95qSI'></tfoot><dl id='95qSI'><fieldset id='95qSI'></fieldset></dl></div>
      <tfoot id='95qSI'></tfoot>
    1. <legend id='95qSI'><style id='95qSI'><dir id='95qSI'><q id='95qSI'></q></dir></style></legend>
    2. 使用 C# 进行查询验证

      Query validation using C#(使用 C# 进行查询验证)

      <small id='pju0z'></small><noframes id='pju0z'>

      <i id='pju0z'><tr id='pju0z'><dt id='pju0z'><q id='pju0z'><span id='pju0z'><b id='pju0z'><form id='pju0z'><ins id='pju0z'></ins><ul id='pju0z'></ul><sub id='pju0z'></sub></form><legend id='pju0z'></legend><bdo id='pju0z'><pre id='pju0z'><center id='pju0z'></center></pre></bdo></b><th id='pju0z'></th></span></q></dt></tr></i><div id='pju0z'><tfoot id='pju0z'></tfoot><dl id='pju0z'><fieldset id='pju0z'></fieldset></dl></div>
        <bdo id='pju0z'></bdo><ul id='pju0z'></ul>

            <tbody id='pju0z'></tbody>
          • <tfoot id='pju0z'></tfoot>
            • <legend id='pju0z'><style id='pju0z'><dir id='pju0z'><q id='pju0z'></q></dir></style></legend>
              1. 本文介绍了使用 C# 进行查询验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在寻找 C# 中的查询验证器,它允许我从文本框中解析 SQL 文本并在发送它执行(MS SQL 或 DB2 查询)之前验证它是否正确.

                I am looking for a query validator in C#, which allows me to parse the SQL text from a textbox and verify whether it's correct or not before sending it for execution (MS SQL or DB2 queries).

                推荐答案

                如果你想在不使用数据库的情况下验证 SQL 语法,TSql100Parser 类将适用于这种情况.

                If you want to validate SQL syntax without the use of a database, the TSql100Parser class will do well for this situation.

                免责声明,此处借用此帖子的代码验证SQL脚本的代码

                Disclaimer, code borrowed from this post here Code to validate SQL Scripts

                虽然使用起来非常简单.如果返回null,则解析没有错误.

                Pretty straightforward to use though. If it returns null, then there were no errors in parsing it.

                using Microsoft.Data.Schema.ScriptDom;
                using Microsoft.Data.Schema.ScriptDom.Sql;
                
                public class SqlParser
                {
                        public List<string> Parse(string sql)
                        {
                            TSql100Parser parser = new TSql100Parser(false);
                            IScriptFragment fragment;
                            IList<ParseError> errors;
                            fragment = parser.Parse(new StringReader(sql), out errors);
                            if (errors != null && errors.Count > 0)
                            {
                                List<string> errorList = new List<string>();
                                foreach (var error in errors)
                                {
                                    errorList.Add(error.Message);
                                }
                                return errorList;
                            }
                            return null;
                        }
                }
                

                这篇关于使用 C# 进行查询验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                C# namespace alias - what#39;s the point?(C# 命名空间别名 - 有什么意义?)
                Using Xpath With Default Namespace in C#(在 C# 中使用具有默认命名空间的 Xpath)
                Generating an EDMX from a DB2 Database(从 DB2 数据库生成 EDMX)
                IBM .NET Data Provider Connection String issue with Library List(库列表的 IBM .NET 数据提供程序连接字符串问题)
                .NET DB2 OLEDB pre-requisites(.NET DB2 OLEDB 先决条件)
                Referring to Code in IBM.Data.DB2 makes that Assembly Unavailable to the rest of my Solution(引用 IBM.Data.DB2 中的代码使该程序集对我的解决方案的其余部分不可用)
                <i id='bEWzO'><tr id='bEWzO'><dt id='bEWzO'><q id='bEWzO'><span id='bEWzO'><b id='bEWzO'><form id='bEWzO'><ins id='bEWzO'></ins><ul id='bEWzO'></ul><sub id='bEWzO'></sub></form><legend id='bEWzO'></legend><bdo id='bEWzO'><pre id='bEWzO'><center id='bEWzO'></center></pre></bdo></b><th id='bEWzO'></th></span></q></dt></tr></i><div id='bEWzO'><tfoot id='bEWzO'></tfoot><dl id='bEWzO'><fieldset id='bEWzO'></fieldset></dl></div>

                  <tfoot id='bEWzO'></tfoot>

                  <small id='bEWzO'></small><noframes id='bEWzO'>

                    • <bdo id='bEWzO'></bdo><ul id='bEWzO'></ul>
                    • <legend id='bEWzO'><style id='bEWzO'><dir id='bEWzO'><q id='bEWzO'></q></dir></style></legend>
                          <tbody id='bEWzO'></tbody>