I have my login form and i tried to parameter the query for logging in user. But it seem to give an error that Login failed for user. My code is here. Please tell me what am i doing wrong here.
public void LoginUser()
{
string UserNameFromHTML = Page.Request.Form["UserNameIput"];
string UserPasswordFromHTML = Page.Request.Form["UserPasswordInput"];
string QueryString = "SELECT User_Id, User_Name, User_Password FROM um_Personnel WHERE User_Name = @UserName and User_Password = @UserPassword";
SqlCommand Command = new SqlCommand();
Command.CommandText = QueryString;
Command.Connection = ConnectionString;
Command.Parameters.AddWithValue("@UserName", UserNameFromHTML);
Command.Parameters.AddWithValue("@UserPassword", UserPasswordFromHTML);
using (SqlDataAdapter Data_Adapter = new SqlDataAdapter(Command))
{
DataSet Data_Set = new DataSet();
Data_Adapter.Fill(Data_Set);
if (Data_Set.Tables[0].Rows.Count > 0)
{
Response.Redirect("CMS/Dashboard.aspx");
}
}
}
and i am calling this function on my button onClick
event as
<button type="submit" class="submit" onclick='<% LoginUser(); %>'>
THE COMPLETE HTML CODE IS HERE
<fieldset>
<legend class="legend">User Login</legend>
<div class="input">
<input type="text" placeholder="Enter User Name" id="UserNameIput" required />
<span><i class="fa fa-envelope-o"></i></span>
</div>
<div class="input">
<input type="password" placeholder="Enter Password" id="UserPasswordInput" required />
<span><i class="fa fa-lock"></i></span>
</div>
<button type="submit" class="submit" onclick='<% LoginUser(); %>'><i class="fa fa-long-arrow-right"></i></button>
</fieldset>