Sayan Chatterjee

Sayan Chatterjee

  • NA
  • 22
  • 2.7k

Check if user exists in database table 'Login' during signup

Aug 9 2017 12:56 PM
 I'm trying to verify whether a new user, while sign-up already exists in the database ('Login' table). Below is the code that I have written. However, it's not checking the 'textboxnewusername.Text' with the existing 'Username' in the 'Login table'. Any idea what to do? The 'Labelmessage' is not displayed in any case!
 
 
protected void Buttonsubmit_Click(object sender, EventArgs e)
{
using (ShopDataContext Data = new ShopDataContext())
{
  
var check = Data.Logins.Where(Login => Login.Username==TextBoxnewusername.Text); //Lambda expression//

foreach (Login output in check)
{
if (output.Username != TextBoxnewusername.Text)
{
Login newlogin = new Login();       //Creating instance of the 'Login' table//
newlogin.Name = TextBoxname.Text;
newlogin.Username = TextBoxnewusername.Text;
newlogin.Address = TextBoxaddress.Text;
newlogin.password = TextBoxnewpassword.Text;

Data.Logins.InsertOnSubmit(newlogin);
Data.SubmitChanges();
Labelmessage.Text = "Successful";
}

else
{
Labelmessage.Text = "User name already exists in the database, pls. select a new username";
}

}
}
}

Answers (1)