本文整理汇总了C#中System.Data.SqlClient.SqlCommand.NextResult方法的典型用法代码示例。如果您正苦于以下问题:C# SqlCommand.NextResult方法的具体用法?C# SqlCommand.NextResult怎么用?C# SqlCommand.NextResult使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.SqlClient.SqlCommand
的用法示例。
在下文中一共展示了SqlCommand.NextResult方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: readFromDataBase
public void readFromDataBase()
{
items.Clear();
SqlDataReader reader = new SqlCommand(string.Format("SELECT * FROM Items ORDER BY Id;SELECT * FROM Jobs ORDER BY Item;SELECT * FROM Jobs ORDER BY Item;"), cn).ExecuteReader();
//читаем лист items
while (reader.Read())
{
item newItem = new item();
newItem.id = reader.GetInt32(0);
newItem.firstName = reader.GetString(1);
newItem.lastName = reader.GetString(2);
items.Add(newItem);
}
int i;
int lastid;
//читаем лист jobs
reader.NextResult();
lastid = i = -1;
while (reader.Read())
{
int k = reader.GetInt32(4);
if (lastid != k)
{
do ++i;
while (k != items[i].id);
lastid = reader.GetInt32(4);
}
items[i].jobs.Add(new job(reader.GetDateTime(0), reader.GetString(1), reader.GetString(2), reader.GetString(3)));
}
//читаем лист positions
reader.NextResult();
lastid = i = -1;
while (reader.Read())
{
if (lastid != reader.GetInt32(4))
{
do i++;
while (reader.GetInt32(4) != items[i].id);
lastid = reader.GetInt32(4);
}
items[i].positions.Add(new position(reader.GetInt64(0),reader.GetInt64(1),reader.GetInt32(2),reader.GetDateTime(3)));
}
reader.Close();
}
示例2: GetLinkedDatabaseList
public List<LinkedDatabase> GetLinkedDatabaseList()
{
if (!this.IsSqlServer)
{
throw new NotSupportedException("This operation is supported only for SQL Server.");
}
StringBuilder builder = new StringBuilder();
List<string> list = new List<string>();
List<LinkedDatabase> list2 = new List<LinkedDatabase>();
string cmdText = "select data_source from sys.servers where provider = 'SQLNCLI' and is_linked = 1";
using (SqlConnection connection = new SqlConnection(this.GetCxString()))
{
SqlDataReader reader;
connection.Open();
using (reader = new SqlCommand(cmdText, connection).ExecuteReader())
{
while (reader.Read())
{
string item = reader[0].ToString();
list.Add(item);
builder.AppendLine("select name from [" + item + "].[master].[sys].[databases]");
}
}
int num = 0;
using (reader = new SqlCommand(builder.ToString(), connection).ExecuteReader())
{
while (reader.Read())
{
list2.Add(new LinkedDatabase(list[num], reader[0].ToString()));
continue;
Label_00D6:
if (!reader.NextResult())
{
return list2;
}
num++;
}
goto Label_00D6;
}
}
}