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
Jayita Roy
NA
22
2.1k
Login problem
Jun 22 2015 10:49 AM
SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;Initial Catalog=db-ub;Integrated Security=True");
try
{
con.Open();
SqlCommand cmd = new SqlCommand(@"SELECT Count(*) FROM Logins
WHERE Username=@uname,
Password=@pass and Category=@ctgy", con);
cmd.Parameters.AddWithValue("@uname", textBox_usern.Text);
cmd.Parameters.AddWithValue("@pass", textBox_pwd.Text);
int result = (int)cmd.ExecuteScalar();
con.Close();
con.Open();
SqlCommand sc1 = new SqlCommand(@"Select Category from Logins
Where Username=@usrn", con);
sc1.Parameters.AddWithValue("@usrn", textBox_usern.Text);
SqlDataReader dr = sc1.ExecuteReader();
while (dr.Read())
{
string ctgy = (string)dr["Logins"];
sc1.Parameters.AddWithValue("@ctgy", ctgy);
if (result > 0)
{
if (ctgy == "Admin")
{
//this.Close();
MessageBox.Show("Welcome Admin");
Admin f1 = new Admin();
f1.Show();
}
else
{
MessageBox.Show("Welcome " + textBox_usern.Text);
FormCheck f5 = new FormCheck();
f5.Show();
}
}
else
{
MessageBox.Show("Incorrect login");
}
textBox_usern.Clear();
textBox_pwd.Clear();
}
}
catch (Exception ex)
{
MessageBox.Show("Unexpected error:" + ex.Message);
}
/* I have a table "Logins" it has 3 column Username, Password and Category. Category has two types "Admin" and "User". Now I have two textbox where user will give Username and Password. I want username textbox input to check whether the given username is Admin or User and open different forms. Now it's showing an error." Please help. */
Reply
Answers (
2
)
how to open windows form use xslt link
can not the "string.Empty" as the default parameter method?