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
Tangara G
NA
298
93.1k
how to check if user is in database already ?
Jul 28 2016 7:05 AM
I have a form which requires new user to register. If they are already in the database, then they will be re-direct to the login page. If not, they can proceed with the user registration.
However, I am not sure what is wrong with my code cos even if the username is not found, it still direct them to the login page.
protected
void
Submit_Button_Click(object sender, EventArgs e)
{
using
(Team6_PhoneOnlineShopEntities2 cntx =
new
Team6_PhoneOnlineShopEntities2())
{
//try
{
// var checkuser = from u in cntx.Users where u.userName == txtUserName.Text select u;
// var checkuser = from u in cntx.Users where txtUserName.Text == u.userName select u;
var checkuser = cntx.Users.FirstOrDefault(u => txtUserName.Text == u.userName);
//int a = Convert.ToInt32(txtUserId.Text);
// var User = cntx.Users.FirstOrDefault(m => m.userID == a);
// customer.userName = txtUserName.Text;
// String checkUser = "select Count(*) from User where userName = '" + customer.userName + "'";
if
(checkuser == null)
{
User customer =
new
User();
customer.userName = txtUserName.Text;
customer.lastName = txtLastName.Text;
customer.userPassword = txtUserPassword.Text;
customer.userPassword = txtConfirmedPassword.Text;
customer.moblieNumber = txtMobileNo.Text;
customer.userAddress = txtAddress.Text;
customer.userEmail = txtEmail.Text;
customer.roleID = 1;
customer.paymentMethod = DropDownList1.SelectedValue;
cntx.Users.Add(customer);
cntx.SaveChanges();
lblMessageSuccess.Text =
"successful registration"
;
}
else
{
lblMessageUser.Text =
"You have registered before. Pls proceed to login"
;
Response.Redirect(
"/Login.aspx"
);
}
}
// Response.Redirect("SuperPhoneOnLineShop_Team6/ShoppingPage");// enter the right url here
}
}
}
}
I hope someone can point out what is the way to do my code so that it will turn out the way I want. Many thanks.
Reply
Answers (
10
)
Not Exporting Ajax ControlToolkit Linechart to excel asp.net
I need to full fill default.aspx on desktop (full size)