ch10_08.cs

来自「《c#技术内幕代码》」· CS 代码 · 共 55 行

CS
55
字号
using System; 
using System.Data; 
using System.Data.SQL;
using System.Data.ADO; 

public class CH10_8
{ 
   public static void Main () 
   { 
       // Define the connection string
       string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=CH10.MDB"; 
       
       // Define our selection criteria
       string strRec = "FindTaxRateForState";
       strRec += " 'WI'";
  
       // Create the connection object, using our connection string
       ADOConnection myConn = new ADOConnection(strConn); 

       // Create the command object from our selection criteria string       
       ADOCommand myCmd = new ADOCommand( strRec, myConn ); 
       myCmd.CommandType = CommandType.StoredProcedure;
       
       // Try to execute the command       
       ADODataReader outData = null; 
       try 
       { 
            // This will do the connection to the database
            myConn.Open(); 
	    
            // This will run our query and put the result in outData
            myCmd.Execute( out outData ); 
	

           // See if we got something back
           if ( outData != null ) 
           { 
                 while (outData.Read() ) 
                 { 
		    // Get the out parameters
		    Console.WriteLine("name = {0}", outData["Name"]);
		    Console.WriteLine("name = {0}", outData["Tax Rate"]);
		    
                 } 
           } 
    
       } 
       catch ( Exception e )
       {
          Console.WriteLine("Exception {0}", e );
       }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?