存储过程中的参数

存储过程中的参数

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

问题描述

Hello Code项目,

我正在使用3层架构在SP中仅传递2个参数(即user_name和password),并且我想为该用户使用表字段数据(即City Name).

Hello Code Project,

I''m using 3 tier architecture & passing only 2 parameter (i.e user_name and password) in SP and I want to use table field data (i.e City Name) for that user.. I want that City Name at Presentation Side, How do I achieve this ?

ALTER PROCEDURE [dbo].[LogInProcedure]
    @username nvarchar (50),
    @password nvarchar (50)
AS
    SET NOCOUNT ON;
SELECT  * FROM users
WHERE   user_username=@username AND user_password=@password



我的问题是,如何从表格到演示方获取城市名称?

在此先感谢:)



My question is, how can get the City Name from table to the Presentation Side ??

Thanks in advance :)

推荐答案


public DataSet ViewUserProfile(string userName, string password)
        {
            SqlConnection con = new SqlConnection(conStr);
            DataSet ds = new DataSet();
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = con;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Clear();
            cmd.CommandText = "proc_GetUserDetails";
            cmd.Parameters.Add(new SqlParameter("@UserName", UserName));
            cmd.Parameters.Add(new SqlParameter("@Password", Password));

            con.Open();
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(ds);
            con.Close();
            return ds;
        }


现在,它将以表格格式返回数据,其中包含您在存储过程中提到的所有列.
因此,您可以在前端使用下面的代码显示值...


Now, this will return data in a tabular format with all the colums you mentioned in the stored procedure.
So, in the front end you can show the values using the code below...

BAlLayer objUser = new BAlLayer();
DataSet ds = objUser.ViewUserProfile(userName, password);

txtCityName.Value = ds.Tables[0].Rows[0]["CityName"].ToString();


这篇关于存储过程中的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 09:37