+ -
当前位置:首页 → 问答吧 → 调试存储过程

调试存储过程

时间:2011-12-07

来源:互联网

C#如何调试存储过程?

作者: hmq7711   发布时间: 2011-12-07

C# code

//此为增删改的操作
            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); //存储过程参数

作者: echoya35   发布时间: 2011-12-07

C# code

//此为查询操作
            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);//存储过程参数


作者: echoya35   发布时间: 2011-12-07

用 sql profiler

作者: Sandy945   发布时间: 2011-12-07

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

C# code

//此为增删改的操作
SqlConnection con = new SqlConnection(YourConnectionStringHere);
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.Comm……

作者: echoya35   发布时间: 2011-12-07