Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
here is my store procedure
SQL
USE [STTKDevelopers]
GO
/****** Object:  StoredProcedure [dbo].[AdminLogin]    Script Date: 06/20/2013 12:12:22 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[AdminLogin]
@Admin_Username nvarchar(10),
@Admin_Password nvarchar(10)
AS
SELECT Admin_Username, Admin_Password
FROM ADMINISTRATOR
WHERE ADMINISTRATOR.Admin_Username LIKE @Admin_Username AND ADMINISTRATOR.Admin_Password = @Admin_Password AND Active = 'Yes'



Here is my code
C#
protected void login_Authenticate(object sender, AuthenticateEventArgs e)
   {

       using (HostingEnvironment.Impersonate())
       {

           string username = loginDetails.UserName;
           string password = loginDetails.Password;

           string s;
           s = WebConfigurationManager.ConnectionStrings["ConnString"].ConnectionString;
           SqlConnection con = new SqlConnection(s);
           con.Open();
           //string sqlUserName;
           //sqlUserName = "SELECT Admin_Username, Admin_Password FROM ADMINISTRATOR WHERE Admin_Username ='" + username + "' AND Admin_Password ='" + pwd + "'";
          // SqlCommand cmd = new SqlCommand(sqlUserName, con);
           SqlCommand cmd = new SqlCommand("AdminLogin", con);
           cmd.CommandType = CommandType.StoredProcedure;


           string CurrentName;
           CurrentName = (string)cmd.ExecuteScalar();

           if (CurrentName != null)
           {
               Session["UserAuthentication"] = username;
               Session.Timeout = 1;
               Response.Redirect("~/Admin/Default.aspx");
           }
           else
           {
               Session["UserAuthentication"] = "";
           }




       }
   }

when i debug i get this error "Procedure or function 'AdminLogin' expects parameter '@Admin_Username', which was not supplied.
"
Posted
Updated 20-Jun-13 1:32am
v2
Comments
_Amy 20-Jun-13 7:45am    
Have a look at Solution 2. :)

Yes, this exception is obvious. In login_Authenticate function, you are calling the same stored procedure "AdminLogin" and that procedure expects the parameters(@Admin_Username and @Admin_Password) which is not supplied. You need to pass both parameters as you are passing in Login function.

[Edit 1]
Try this code:
C#
SqlCommand cmd = new SqlCommand("AdminLogin", con);
cmd.CommandType = CommandType.StoredProcedure;
//Adding the required parameters
cmd.Parameters.AddWithValue("@Admin_Username", YourUserName);//Pass username
cmd.Parameters.AddWithValue("@Admin_Password", YourPassword);//pass password

string CurrentName;
CurrentName = (string)cmd.ExecuteScalar();


--Amit
 
Share this answer
 
v2
Comments
db_developer 24-Jun-13 19:26pm    
I agree with answer and want to add:

your query can return more than 1 row and will return 2 columns, therefore ExecuteScalar() is not acceptable.
Use ExecuteReader() and Reader.ReadLine then.
or
edit procedure query using SELECT TOP 1 AdminName at beginning.
You need to pass parameters as

C#
cmd.Parameters.AddWithValue("@Admin_Username", username );
cmd.Parameters.AddWithValue("@Admin_Password", password);



below the line

cmd.CommandType = CommandType.StoredProcedure;
 
Share this answer
 
v2
Try without the @ for paramater.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900