需要有关存储过程视图数据的帮助

时间:2022-04-06 02:02:24

Somebody please help me by modying this code.when i retrieve the Login value through stored procedure call, i am getting this error message "Procedure or function 'GetUserLogin' expects parameter '@UserName', which was not supplied." Here is my code:

有人请通过修改此代码来帮助我。当我通过存储过程调用检索Login值时,我收到此错误消息“过程或函数'GetUserLogin'期望参数'@UserName',这是未提供的。”这是我的代码:

public int GetLogin(string UserName, string Password)
    {
        SqlConnection con = new SqlConnection(str);      
        SqlDataAdapter da = new SqlDataAdapter("GetUserLogin", con);
        SqlCommand com = new SqlCommand("GetUserLogin",con);     
        com.CommandType = CommandType.StoredProcedure;
        DataSet ds = new DataSet();
        da.Fill(ds);
        if (ds.Tables[0].Rows.Count > 0)
        {
            if ((ds.Tables[0].Rows[0].ItemArray[1].ToString() == UserName) && (ds.Tables[0].Rows[0].ItemArray[2].ToString() == Password))
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }
        else
        {
            return -1;
        }
StoredProcedure:
CREATE PROCEDURE GetUserLogin @UserName varchar(50)   
AS
select UserName,
       Password
From Login where UserName=@UserName
    RETURN

Thanks, Masum

2 个解决方案

#1


You need to add a UserName parameter to your command. Do something like this after you create your command, but before you execute it:

您需要在命令中添加UserName参数。在创建命令之后但在执行命令之前执行类似的操作:

com.Parameters.Add("@UserName", SqlDbType.VarChar, 50);
com.Parameters["@UserName"].Value = UserName;

#2


Add this before you fill the dataset

在填充数据集之前添加此项

cmd.Parameters.AddWithValue("UserName",UserName);

#1


You need to add a UserName parameter to your command. Do something like this after you create your command, but before you execute it:

您需要在命令中添加UserName参数。在创建命令之后但在执行命令之前执行类似的操作:

com.Parameters.Add("@UserName", SqlDbType.VarChar, 50);
com.Parameters["@UserName"].Value = UserName;

#2


Add this before you fill the dataset

在填充数据集之前添加此项

cmd.Parameters.AddWithValue("UserName",UserName);