上传者: codesky01
|
上传时间: 2021-12-06 13:20:43
|
文件大小: 11.47MB
|
文件类型: -
c#高级编程(第10版)源码.
using Microsoft.Extensions.Configuration;
using System;
using System.Data;
using System.Data.SqlClient;
using static System.Console;
namespace CommandSamples
{
class Program
{
static void Main(string[] args)
{
if (args.Length != 1)
{
ShowUsage();
return;
}
switch (args[0])
{
case "-nq":
ExecuteNonQuery();
break;
case "-s":
ExecuteScalar();
break;
case "-r":
ExecuteReader(717);
break;
case "-sp":
StoredProcedure(251);
break;
default:
ShowUsage();
break;
}
ReadLine();
}
private static void StoredProcedure(int entityId)
{
using (var connection = new SqlConnection(GetConnectionString()))
{
SqlCommand command = connection.CreateCommand();
command.CommandText = "[dbo].[uspGetEmployeeManagers]";
command.CommandType = CommandType.StoredProcedure;
SqlParameter p1 = command.CreateParameter();
p1.SqlDbType = SqlDbType.Int;
p1.ParameterName = "@BusinessEntityID";
p1.Value = entityId;
command.Parameters.Add(p1);
connection.Open();
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
int recursionLevel = (int)reader["RecursionLevel"];
int businessEntityId = (int)reader["BusinessEntityID"];
string firstName = (string)reader["FirstName"];
string lastName = (string)reade