zoukankan      html  css  js  c++  java
  • 调用存储过程

    using System;
    using System.Data;
    using System.Data.SqlClient;
    
    /*
    	create procedure sp_Select_All_Employees
    	as
    	  select
    		employeeid,
    		firstname,
    		lastname
    	  from
    		employees
    */
    namespace Chapter6
    {
        class CallSp1
        {
            static void Main()
            {
               
                SqlConnection conn = null;
                SqlDataReader rdr = null;
                try
                {
                     // create connection
                     conn = new SqlConnection
                                            (@"server = .;
                                            integrated security = true;
                                            database = northwind");
    
                    // open connection
                    conn.Open();
                    
                    // create command
                     SqlCommand cmd = conn.CreateCommand();
    
                    // specify stored procedure to  execute
                    //enum CommandType {Text, StoredProcedure, TableDirect}
                     cmd.CommandType = CommandType.StoredProcedure;
                    //指定StoredProcedure名
                     cmd.CommandText = "sp_Select_All_Employees";
    
                     // execute command
                     rdr = cmd.ExecuteReader();
    
                     // Process the result set
                     while (rdr.Read())
                     {
                         Console.WriteLine(
                         "{0} {1} {2}"
                         ,rdr[0].ToString().PadRight(5)
                         ,rdr[1].ToString()
                         ,rdr[2].ToString());                
                     }
                     
                }
                catch (SqlException ex)
                {
                     Console.WriteLine(ex.ToString());
                }
                finally
                {
                    rdr.Close();
                    conn.Close();
                }
            }
        }
    }
  • 相关阅读:
    python3之Django内置模板标签和过滤器
    JavaScript(1)
    python3之Django基础篇
    CSS
    HTML
    python3之SQLAlchemy
    python3之memcached
    web服务器-nginx虚拟主机
    web服务器-nginx默认网站
    web服务器-Nginx下载限速
  • 原文地址:https://www.cnblogs.com/java20130722/p/3207230.html
Copyright © 2011-2022 走看看