存储过程的输出参数asp.net C# [英] Stored procedure output parameter asp.net c#

查看:110
本文介绍了存储过程的输出参数asp.net C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的存储过程的世界。

I'm new to stored procedure world.

我们现有的系统与现有的存储过程,检查用户名和URL路径。存储过程将检查用户的详细信息是否存在。如果存在,返回值为1,如果没有返回值0

We have existing system with existing stored procedure, which checks username and url path. Stored procedure will check whether user details exist. If exists return value 1 if not return value 0

我要的是写asp.net C#code此存储过程。传递用户信息和路径,之后返回0或1。

All I want is writing asp.net c# code for this stored procedure. Passing user details and path and returning 0 or 1 after that.

如果返回值是1,允许用户如果0然后重定向到不同的页面

If return value is 1, allow user if it 0 then redirect to different page

下面链接的SQL Server执行存储过程

Below link for SQL Server execute stored procedure

http://www.natboxservices.com/helmshore/img/pic.jpg

pciated任何帮助AP $ P $

any help appreciated

感谢

推荐答案

看起来像你需要存储过程输出参数

Looks like you need stored procedure with output parameter

int errorId = 0;

using(SqlConnection sqlConnection = new SqlConnection(connectionString))
{
    using(SqlCommand cmd = new SqlCommand("YourStoredProcedureName", sqlConnection))
    {
    cmd.CommandType=CommandType.StoredProcedure;
    SqlParameter parm=new SqlParameter("@username", SqlDbType.VarChar); 
    parm.Value="mshiyam";
    parm.Direction =ParameterDirection.Input ; 
    cmd.Parameters.Add(parm); 

    SqlParameter parm2=new SqlParameter("@path",SqlDbType.VarChar); 
    parm2.value = "Some Path";
    parm2.Direction=ParameterDirection.Output;
    cmd.Parameters.Add(parm2); 


    SqlParameter parm3 = new SqlParameter("@errorId",SqlDbType.Int);
    parm3.Direction=ParameterDirection.Output; 
    cmd.Parameters.Add(parm3); 

    sqlConnection.Open(); 
    sqlConnection.ExecuteNonQuery();

    errorId = cmd.Parameters["@errorId"].Value; //This will 1 or 0
   }

}

这篇关于存储过程的输出参数asp.net C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆