TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
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";
}
}
}
}
Reply
Answers (
1
)
Viewing uploaded files
Looking for book on MVC Core C# Programming