カタログ操作の実行Performing Catalog Operations

データベースまたは CREATE TABLE または CREATE PROCEDURE ステートメントなどのカタログを変更するコマンドを実行するには、作成、コマンドオブジェクト、適切な SQL ステートメントを使用して、接続オブジェクト。To execute a command to modify a database or catalog, such as the CREATE TABLE or CREATE PROCEDURE statement, create a Command object using the appropriate SQL statements and a Connection object. コマンドを実行、 ExecuteNonQueryのメソッド、コマンドオブジェクト。Execute the command with the ExecuteNonQuery method of the Command object.

Microsoft SQL Server データベースにストアド プロシージャを作成するコード サンプルを次に示します。The following code example creates a stored procedure in a Microsoft SQL Server database.

' Assumes connection is a valid SqlConnection.  
Dim queryString As String = "CREATE PROCEDURE InsertCategory " & _  
    "@CategoryName nchar(15), " & _  
    "@Identity int OUT " & _  
    "AS " & _  
    "INSERT INTO Categories (CategoryName) VALUES(@CategoryName) " & _  
    "SET @Identity = @@Identity " & _  
    "RETURN @@ROWCOUNT"  
  
Dim command As SqlCommand = New SqlCommand(queryString, connection)  
command.ExecuteNonQuery()  
// Assumes connection is a valid SqlConnection.  
string queryString = "CREATE PROCEDURE InsertCategory  " +   
    "@CategoryName nchar(15), " +  
    "@Identity int OUT " +  
    "AS " +   
    "INSERT INTO Categories (CategoryName) VALUES(@CategoryName) " +   
    "SET @Identity = @@Identity " +  
    "RETURN @@ROWCOUNT";  
  
SqlCommand command = new SqlCommand(queryString, connection);  
command.ExecuteNonQuery();  

関連項目See also