using (SqlCommand command = new SqlCommand("SELECT * FROM Customers WHERE CustomerID = @CustomerID", connection)) { command.CommandType = CommandType.Text; command.Parameters.Add("@CustomerID", SqlDbType.Int).Value = customerId; // execute the query here }
using (SqlCommand command = new SqlCommand("my_stored_procedure", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.Add("@FirstName", SqlDbType.VarChar, 50).Value = firstName; // execute the stored procedure here }The package library for DbType is part of the System.Data.Common package.