C#如何调试存储过程?

解决方案 »

  1.   


    //此为增删改的操作
                SqlConnection con = new SqlConnection(YourConnectionStringHere);
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = con;
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "YourProcedureHere"; //存储过程名
                
                //参数为一个或多个 也可以没有 根据你的存储过程来决定
                cmd.Parameters.Add("YourYourProcedureArgument",value); //存储过程参数
                cmd.Parameters.Add("YourYourProcedureArgument",value); //存储过程参数
      

  2.   


    //此为查询操作
                DataSet ds = new DataSet();
                SqlDataAdapter da = new SqlDataAdapter();
                da.SelectCommand = new SqlCommand();
                da.SelectCommand.Connection = new SqlConnection(YourConnectionStringHere);
                da.SelectCommand.CommandType = CommandType.StoredProcedure;
                da.SelectCommand.CommandText = "YourProcedureHere";//存储过程名            da.SelectCommand.Parameters.Add("YourYourProcedureArgument",value);//存储过程参数
      

  3.   

    补充: 用cmd.ExecNoneQuery()执行  cmd.Parameters.Add 在VS2010中提示已过时 但不影响执行 建议存储过程的参数名与数据库中的存储过程的参数名字一致(此为Sql Server 2008 R2 的库)