C#里调用带输出参数的存储过程
生活随笔
收集整理的這篇文章主要介紹了
C#里调用带输出参数的存储过程
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
C#里調用帶輸出參數的存儲過程 ?1using?System;
?2using?System.Collections.Generic;
?3using?System.Linq;
?4using?System.Text;
?5using?System.Threading;
?6using?System.Data;
?7using?System.Data.SqlClient;
?8namespace?ConsoleApplicationTest
?9{
10????class?Program
11????{
12????????static?void?Main(string[]?args)
13????????{
14????????????try
15????????????{
16????????????????//connection對象
17????????????????string?strConn?=?"Data?Source=.;uid=sa;pwd=wzb0227;Integrated?Security=SSPI;Initial?Catalog=Evaluation;Integrated?Security=True";
18????????????????SqlConnection?conn?=?new?SqlConnection(strConn);
19????????????????conn.Open();
20????????????????//command對象
21????????????????SqlCommand?comm?=?new?SqlCommand("getCountNum",?conn);
22????????????????comm.CommandType?=?CommandType.StoredProcedure;
23????????????????//填充參數
24????????????????SqlParameter?para?=?new?SqlParameter("@count",?SqlDbType.Int);
25????????????????para.Direction?=?ParameterDirection.Output;
26????????????????comm.Parameters.Add(para);
27????????????????//執行,取輸出參數
28????????????????comm.ExecuteNonQuery();
29????????????????int?count?=?(int)comm.Parameters["@count"].Value;
30????????????????conn.Close();
31????????????????Console.WriteLine("count="?+?count);
32????????????}
33????????????catch
34????????????{
35????????????????Console.WriteLine("出現了異常!");
36????????????}
37????????}
38????}
39} posted on 2008-12-19 10:57 彬子 閱讀(...) 評論(...) 編輯 收藏
?2using?System.Collections.Generic;
?3using?System.Linq;
?4using?System.Text;
?5using?System.Threading;
?6using?System.Data;
?7using?System.Data.SqlClient;
?8namespace?ConsoleApplicationTest
?9{
10????class?Program
11????{
12????????static?void?Main(string[]?args)
13????????{
14????????????try
15????????????{
16????????????????//connection對象
17????????????????string?strConn?=?"Data?Source=.;uid=sa;pwd=wzb0227;Integrated?Security=SSPI;Initial?Catalog=Evaluation;Integrated?Security=True";
18????????????????SqlConnection?conn?=?new?SqlConnection(strConn);
19????????????????conn.Open();
20????????????????//command對象
21????????????????SqlCommand?comm?=?new?SqlCommand("getCountNum",?conn);
22????????????????comm.CommandType?=?CommandType.StoredProcedure;
23????????????????//填充參數
24????????????????SqlParameter?para?=?new?SqlParameter("@count",?SqlDbType.Int);
25????????????????para.Direction?=?ParameterDirection.Output;
26????????????????comm.Parameters.Add(para);
27????????????????//執行,取輸出參數
28????????????????comm.ExecuteNonQuery();
29????????????????int?count?=?(int)comm.Parameters["@count"].Value;
30????????????????conn.Close();
31????????????????Console.WriteLine("count="?+?count);
32????????????}
33????????????catch
34????????????{
35????????????????Console.WriteLine("出現了異常!");
36????????????}
37????????}
38????}
39} posted on 2008-12-19 10:57 彬子 閱讀(...) 評論(...) 編輯 收藏
轉載于:https://www.cnblogs.com/wangzb/archive/2008/12/19/1358124.html
總結
以上是生活随笔為你收集整理的C#里调用带输出参数的存储过程的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Linux中.a,.la,.o,.so文
- 下一篇: c# char unsigned_dll