本文整理汇总了C#中StoredProcedure.GetDataSet方法的典型用法代码示例。如果您正苦于以下问题:C# StoredProcedure.GetDataSet方法的具体用法?C# StoredProcedure.GetDataSet怎么用?C# StoredProcedure.GetDataSet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StoredProcedure
的用法示例。
在下文中一共展示了StoredProcedure.GetDataSet方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestExistingClosedConnection
public void TestExistingClosedConnection()
{
using (DbConnection connection = GetConnection())
{
const int startId = 2;
const int endId = 3;
Assert.AreEqual(ConnectionState.Closed, connection.State, "The connection should be closed");
StoredProcedure sp = new StoredProcedure("GetNames", "default");
sp.Command.AddParameter("@StartId", startId, DbType.Int32, 4);
sp.Command.AddParameter("@EndId", endId, DbType.Int32, 4);
DataSet ds = sp.GetDataSet(connection);
Assert.AreEqual(ConnectionState.Closed, connection.State, "The connection should stay closed");
DataTable table = ds.Tables[0];
Assert.AreEqual(endId - startId + 1, table.Rows.Count, "The table does not contain the correct number of rows");
}
}
示例2: SP_DSTest
public void SP_DSTest()
{
StoredProcedure sp = new StoredProcedure("CustOrderHist", DataService.GetInstance("Northwind"));
sp.Command.AddParameter("@CustomerID", "ALFKI", DbType.AnsiString);
DataSet ds = sp.GetDataSet();
Assert.IsTrue(ds.Tables[0].Rows.Count > 0);
}
示例3: GenerateReturnSet
/// <summary>
/// Data retrieval
/// </summary>
/// <returns></returns>
private DataSet GenerateReturnSet()
{
DataSet result = null;
if(_url != null)
{
Query q;
if(!String.IsNullOrEmpty(_url.TableName))
{
q = new Query(_url.TableName);
TableSchema.Table schema = q.Schema;
if(_url.PrimaryKey != null)
q.WHERE(q.Schema.PrimaryKey.ParameterName, _url.PrimaryKey);
if(_url.Parameters != null)
{
IDictionaryEnumerator loopy = _url.Parameters.GetEnumerator();
TableSchema.TableColumn column;
string paramName;
object paramValue;
while(loopy.MoveNext())
{
paramName = loopy.Key.ToString();
paramValue = loopy.Value;
if(paramName.ToLowerInvariant() == "pagesize" || paramName.ToLowerInvariant() == "pageindex")
{
if(paramName.ToLowerInvariant() == "pagesize")
q.PageSize = int.Parse(paramValue.ToString());
if(paramName.ToLowerInvariant() == "pageindex")
q.PageIndex = int.Parse(paramValue.ToString());
}
else
{
Comparison comp;
EvalComparison(paramName, out paramName, out comp);
column = schema.GetColumn(paramName);
//if this column is a string, by default do a fuzzy search
if(comp == Comparison.Like || column.IsString)
{
comp = Comparison.Like;
paramValue = String.Concat("%", paramValue, "%");
}
else if(paramValue.ToString().ToLower() == "null")
paramValue = DBNull.Value;
q.WHERE(column.ColumnName, comp, paramValue);
}
}
}
result = q.ExecuteDataSet();
}
else if(!String.IsNullOrEmpty(_url.SpName))
{
StoredProcedure sp = new StoredProcedure(_url.SpName);
if(_url.Parameters != null)
{
IDictionaryEnumerator loopy = _url.Parameters.GetEnumerator();
while(loopy.MoveNext())
sp.Command.AddParameter(loopy.Key.ToString(), loopy.Value, DbType.AnsiString);
}
result = sp.GetDataSet();
}
}
return result;
}
示例4: TestGetDataSet
public void TestGetDataSet()
{
const int startId = 2;
const int endId = 3;
StoredProcedure sp = new StoredProcedure("GetNames", "default");
sp.Command.AddParameter("@StartId", startId, DbType.Int32, 4);
sp.Command.AddParameter("@EndId", endId, DbType.Int32, 4);
DataSet ds = sp.GetDataSet();
DataTable table = ds.Tables[0];
Assert.AreEqual(endId - startId + 1, table.Rows.Count, "The table does not contain the correct number of rows");
for (int i = 0; i < table.Rows.Count; ++i)
{
Assert.AreEqual(i + startId, table.Rows[i][0], "The row is incorrect");
Assert.AreEqual(string.Format("name{0}", i + startId), table.Rows[i][1], "The row is incorrect");
}
}