Performing Catalog Operations
This page is specific to:.NET Framework Version:1.12.03.03.54.0
.NET Framework Developer's Guide
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

© 2009 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View