日期:2014-05-17  浏览次数:20453 次

有哪位大神知道这个代码的错误?错误提示必须声明标量变量@MyProductID
namespace zmf_test1
{
    class Program
    {
        static void Main(string[] args)
        {
            SqlConnection dataConnection = new SqlConnection();
            try
            {
                SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
                //  builder.DataSource = ".\\SQLExpress";
                builder.DataSource = "maggie-PC";
                builder.InitialCatalog = "Northwind";
                builder.IntegratedSecurity = true;
                dataConnection.ConnectionString = builder.ConnectionString;
                dataConnection.Open();

                Console.Write("Please enter a ProductName (less than 2 characters): ");
                string productName = Console.ReadLine();

                SqlCommand dataCommand = new SqlCommand();
                dataCommand.Connection = dataConnection;
                dataCommand.CommandType = CommandType.Text;
                dataCommand.CommandText =
                    "CREATE PROCEDURE AddProduct  @MyProductID int OUTPUT,   @MyProductName nvarchar(40),   @MySupplierID int,   @MyCategoryID int,  @MyQuantityPerUnit nvarchar(20), @MyUnitPrice money,  @MyUnitsInStock smallint,   @MyUnitsOnOrder smallint,    @MyReorderLevel smallint,     @MyDiscontinued bit" +
                    " AS INSERT INTO Products (  ProductName, SupplierID, CategoryID, QuantityPerUnit,  UnitPrice, UnitsInStock, UnitsOnOrder, ReorderLevel,  Discontinued) "+
                    " VALUES (  @MyProductName, @MySupplierID, @MyCategoryID, @MyQuantityPerUnit, "+