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)
{
{
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";
}
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";
}
}
}
}
Nilesh ShahPosted Aug 9, 2017, 1:24 PM
it seems to me simple if - else logic problem.
you are fetching all records where login name is same as entered by user. then you loop thru that data only, and inside that you are checking if login names equals or not!