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
judy lim
NA
2
2.9k
Database Connection
Oct 16 2011 8:58 AM
I am using visual studio 2010. I had created a registration page and login in page. In the registration page, user had to key in username and password and it will be store in the database. How do I link the database from registration page to login page so that I can check whether the user had key in the correct password or whether the user had registered aldready.
I'm using c# and Microsoft SQL management studio.
Thank you in advance.
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection conDatabase = null;
string username = TextBox1.Text;
string password = TextBox2.Text;
SqlConnection connection = null;
SqlCommand command = null;
SqlDataReader dataReader = null;
try
{
string connectionString = ConfigurationManager.ConnectionStrings["TestConnectionString"].ConnectionString;
connection = new SqlConnection(connectionString);
connection.Open();
//prepare sql statements
string sql = "SELECT * from Staff where username='" + username + "'And Password='" + password + "'";
command = new SqlCommand(sql, connection);
dataReader = command.ExecuteReader();
while (dataReader.Read())
{
username = dataReader.GetString(3);
Session.Add("username", username);
}
dataReader.Close();
}
catch catch (IndexOutOfRangeException)
{
username.Text = "";
password.Text = "";
{
Response.Write(ex.Message);
}
May I know if this is correct or do I need to add more things?
Reply
Answers (
1
)
Crystal Reports
Merging certificate(.crt) and private key(.key) into one .pfx file