Stored procedures 需要存储过程视图数据方面的帮助吗
有人请帮我修改此代码。当我通过存储过程调用检索登录值时,我收到错误消息“过程或函数'GetUserLogin'需要参数'@UserName',但未提供该参数。” 这是我的密码:Stored procedures 需要存储过程视图数据方面的帮助吗,stored-procedures,Stored Procedures,有人请帮我修改此代码。当我通过存储过程调用检索登录值时,我收到错误消息“过程或函数'GetUserLogin'需要参数'@UserName',但未提供该参数。” 这是我的密码: public int GetLogin(string UserName, string Password) { SqlConnection con = new SqlConnection(str); SqlDataAdapter da = new SqlDataAdap
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
谢谢,
Masum在填充数据集之前添加此项
cmd.Parameters.AddWithValue(“用户名”,用户名)代码>您需要在命令中添加用户名参数。在创建命令后,但在执行命令之前,请执行以下操作:
com.Parameters.Add("@UserName", SqlDbType.VarChar, 50);
com.Parameters["@UserName"].Value = UserName;
不,你没有,否则我会有几千行坏代码,它们肯定没有坏。