Export (0) Print
Expand All

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 object using the appropriate SQL statements and a Connection object. 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.

// 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 " +

SqlCommand command = new SqlCommand(queryString, connection);
© 2014 Microsoft