C#里调用带输出参数的存储过程 1usingSystem;
2usingSystem.Collections.Generic;
3usingSystem.Linq;
4usingSystem.Text;
5usingSystem.Threading;
6usingSystem.Data;
7usingSystem.Data.SqlClient;
8namespaceConsoleApplicationTest
9{
10classProgram
11{
12staticvoidMain(string[]args)
13{
14try
15{
16//connection对象
17stringstrConn="DataSource=.;uid=sa;pwd=wzb0227;IntegratedSecurity=SSPI;InitialCatalog=Evaluation;IntegratedSecurity=True";
18SqlConnectionconn=newSqlConnection(strConn);
19conn.Open();
20//command对象
21SqlCommandcomm=newSqlCommand("getCountNum",conn);
mandType=CommandType.StoredProcedure;
23//填充参数
24SqlParameterpara=newSqlParameter("@count",SqlDbType.Int);
25para.Direction=ParameterDirection.Output;
26comm.Parameters.Add(para);
27//执行,取输出参数
28comm.ExecuteNonQuery();
29intcount=(int)comm.Parameters["@count"].Value;
30conn.Close();
31Console.WriteLine("count="+count);
32}
33catch
34{
35Console.WriteLine("出现了异常!");
36}
37}
38}
39} posted on -12-19 10:57 彬子 阅读(...) 评论(...) 编辑 收藏