Hello all, 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:
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
From stackoverflow
-
Add this before you fill the dataset
cmd.Parameters.AddWithValue("UserName",UserName);Aheho : This won't work. You need to use "@Username"JoshBerke : No you don't, otherwise I'd have a few thousand lines of broken code which are surely not broken. -
You need to add a UserName parameter to your command. Do something like this after you create your command, but before you execute it:
com.Parameters.Add("@UserName", SqlDbType.VarChar, 50); com.Parameters["@UserName"].Value = UserName;
0 comments:
Post a Comment