I have been working on this piece of code for a long time now and still get error after several modifications.
This is my DataBase Class
public DataTable ExecuteSP(string UserName, string Password)
{
con = new SqlConnection(@"Data Source=My-PC;Initial Catalog=MyDB;Integrated Security=True");
con.Open();
cmd = new SqlCommand("LoginUser", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@UserName", SqlDbType.NVarChar, 20).Value = UserName;
cmd.Parameters.Add("@Password", SqlDbType.NVarChar, 20).Value = Password;
da = new SqlDataAdapter(cmd);
da.Fill(dt);
con.Close();
return dt;
}this is my C# code:
dt = new DataTable();
dt = dbClass.ExecuteSP(UserName, Password);
if (dt.Rows.Count > 0)
{
boolReturnValue = true;
Session["UserId"] = dt.Rows[0]["Id"].ToString();
string updateLastLogin = "Update [User] SET LastLogin='" + System.DateTime.Now.ToString() + "' where Id='" + Session["UserId"].ToString() + "'";
dbClass.ConnectDataBaseToInsert(updateLastLogin);
}This is my stored procedure:
CREATE PROCEDURE [dbo].[LoginUser] (
@UserName nvarchar(20),
@Password nvarchar(20)
)
AS
SET NOCOUNT ON;
(
SELECT * FROM [User] WHERE Email = @UserName AND Password = @Password
)
When I run this work I get error message the says: Could not find stored procedure
Please can someone review this critically and tell me what is wrong with the code.