当前位置: 首页>>代码示例>>C#>>正文


C# SqlQuery.AddParameter方法代码示例

本文整理汇总了C#中SqlQuery.AddParameter方法的典型用法代码示例。如果您正苦于以下问题:C# SqlQuery.AddParameter方法的具体用法?C# SqlQuery.AddParameter怎么用?C# SqlQuery.AddParameter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SqlQuery的用法示例。


在下文中一共展示了SqlQuery.AddParameter方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: From

        public static DataSet From(Transaction pTransaction, string pSelectQuery, DataFieldCollection pConditionalParameters)
        {
            bool lSplitQuery = false;

            List<string> lQueries = new List<string>();

            SqlQuery lSelect;

            DataSet lReturn = new DataSet();

            DataTable lTable;

            if (pTransaction.DataBase.DataBaseType == 0 && pSelectQuery.Contains("-- table"))
            {
                lSplitQuery = true;

                //divide queries que tem mais de uma tabela em várias queries diferentes,
                //pra pegar no oracle. o indicador deve estar no formato:
                // -- table XX
                // com dois traços, um espaço, a palavra "table" em lower case, outro espaco,
                // e o numero da tabela com pad de 1 zero. suporta até 99 tabelas, e a tabela zero não
                // precisa de indicador.

                byte lCounter = 1;

                int lStartIndex = 0, lEndIndex = 0;

                string lFormat = "-- table {0}";

                string lTempQuery, lPreviousTable = "", lCurrentTable = "";

                while (lCurrentTable == "" || pSelectQuery.Contains(lCurrentTable))
                {
                    lCurrentTable = string.Format(lFormat, lCounter.ToString().PadLeft(2, '0'));

                    if (lPreviousTable != "")
                        lStartIndex = pSelectQuery.IndexOf(lPreviousTable);

                    lEndIndex = pSelectQuery.IndexOf(lCurrentTable);

                    if (lEndIndex == -1) lEndIndex = pSelectQuery.Length;

                    lTempQuery = pSelectQuery.Substring(lStartIndex, lEndIndex - lStartIndex);

                    lQueries.Add(lTempQuery);

                    lPreviousTable = lCurrentTable;

                    lCounter++;
                }
            }
            else
            {
                lQueries.Add(pSelectQuery);
            }

            for (int a = 0; a < lQueries.Count; a++)
            {
                lSelect = new SqlQuery(pTransaction, lQueries[a]);

                if (pConditionalParameters != null)
                {
                    foreach (DataField lField in pConditionalParameters.Keys)
                    {
                        if (lSelect.Query.Contains(string.Format(">>{0}", lField.Name)))
                            lSelect.AddParameter(lField.Name, pConditionalParameters[lField]);
                    }
                }

                if (lSplitQuery)
                {
                    lTable = lSelect.ExecuteDataTable().Copy();

                    lTable.TableName = string.Format("Table {0}", a);

                    lReturn.Tables.Add(lTable);
                }
                else
                {
                    //não tem problema estar dentro do loop pq vai ser sempre 1 query só,
                    //mas retornando várias tabelas no dataset
                    lReturn = lSelect.ExecuteDataSet();
                }
            }

            return lReturn;
        }
开发者ID:andreibaptista,项目名称:DEF_PUB_LOTACAO,代码行数:87,代码来源:Select.cs


注:本文中的SqlQuery.AddParameter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。