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?