Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
1
Reply
Check if user exists in database table 'Login' during signup
Sayan Chatterjee
Aug 9 2017 12:56 PM
167
Reply
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";
}
}
}
}
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
1
)
Next Recommended Forum
Viewing uploaded files
Looking for book on MVC Core C# Programming