• 调用存储过程


    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();
                }
            }
        }
    }
  • 相关阅读:
    android焦点
    URI和URL的区别比较与理解
    Android Bundle类
    repo命令
    ubuntu adb找不到设备
    【python】-网络编程
    【python】-反射
    【python】-类的特殊成员方法
    【python】-7-面向对象的进阶
    【python】-多态
  • 原文地址:https://www.cnblogs.com/java20130722/p/3207230.html
Copyright © 2020-2023  润新知