C# 读取在存储过程多结果集
生活随笔
收集整理的這篇文章主要介紹了
C# 读取在存储过程多结果集
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
--SQL Server 測試環(huán)境搭建:
Create database Test; go USE [Test] GO if OBJECT_ID('Tab','U') is not nulldrop table Tab go CREATE TABLE [dbo].[Tab]([ID] [int] identity(1,1) NOT NULL,[name] [sysname] NOT NULL, ) go if OBJECT_ID('Tab2','U') is not nulldrop table Tab2 go CREATE TABLE [dbo].[Tab2]([ID] [int] IDENTITY(1,1) NOT NULL,[TabID] [int] NOT NULL,[Name2] [nvarchar](50) NULL ) ON [PRIMARY] GO--創(chuàng)建存儲(chǔ)過程:if OBJECT_ID('P3','P') is not nulldrop procedure P3 go create procedure P3 as select * from Tab; select * from Tab2;--打開Visual Studio—?jiǎng)?chuàng)建項(xiàng)目—選擇【控制臺(tái)應(yīng)用程序】#region Using Directives using System; using System.Data; using System.Data.SqlClient; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; #endregionnamespace TestReadingStoreProc {class Program{static void Main(string[] args){SqlConnection thisConnection = new SqlConnection(@"Server=(Local);Database=Test;User ID=sa;Password=1"); SqlCommand thisCommand = thisConnection.CreateCommand();thisCommand.CommandType = CommandType.StoredProcedure;thisCommand.CommandText = "P3";SqlDataAdapter thisAdapter = new SqlDataAdapter(thisCommand);DataSet thisDataSet = new DataSet();thisAdapter.Fill(thisDataSet);if (thisDataSet.Tables.Count > 0){Console.WriteLine("Table Name:{0}\nTable Rows:{1}",thisDataSet.Tables[0].TableName, thisDataSet.Tables[0].Rows.Count);Console.WriteLine("Table Name:{0}\nTable Rows:{1}", thisDataSet.Tables[1].TableName, thisDataSet.Tables[1].Rows.Count);}thisConnection.Close();Console.ReadKey();}} }----按F5運(yùn)行結(jié)果:
轉(zhuǎn)載于:https://www.cnblogs.com/wuxi88/p/5466726.html
總結(jié)
以上是生活随笔為你收集整理的C# 读取在存储过程多结果集的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: UVA 1622 Robot
- 下一篇: c# char unsigned_dll