Share via


Performing Catalog Operations

To execute a command to modify a database or catalog, such as the CREATE TABLE or CREATE PROCEDURE statement, create a Command using the appropriate Transact-SQL statement(s) and Connection. Execute the command with the ExecuteNonQuery method of the Command object.

The following code example creates a stored procedure in a Microsoft SQL Server database.

Dim createStr As String = "CREATE PROCEDURE InsertCategory  " & _
                          "  @CategoryName nchar(15), " & _
                          "  @Identity int OUT " & _
                          "AS " & _
                          "INSERT INTO Categories (CategoryName) VALUES(@CategoryName) " & _
                          "SET @Identity = @@Identity " & _
                          "RETURN @@ROWCOUNT"

Dim createCMD As SqlCommand = New SqlCommand(createStr, nwindConn)
createCMD.ExecuteNonQuery()
[C#]string createStr = "CREATE PROCEDURE InsertCategory  " + 
                          "  @CategoryName nchar(15), " +
                          "  @Identity int OUT " +
                          "AS " + 
                          "INSERT INTO Categories (CategoryName) VALUES(@CategoryName) " + 
                          "SET @Identity = @@Identity " +
                          "RETURN @@ROWCOUNT";

SqlCommand createCMD = new SqlCommand(createStr, nwindConn);
createCMD.ExecuteNonQuery();

See Also

Using .NET Framework Data Providers to Access Data | Performing Database Operations and Modifying Data