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