Connection database

  • 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.

  • There are numerous tutorials on internet on how to connect to sql server. Go through them.

    http://www.codeproject.com/KB/database/sql_in_csharp.aspx

  • string username = TextBox1.Text;

    string password = TextBox2.Text;

    OleDbConnection connection = null;

    OleDbCommand command = null;

    OleDbDataReader dataReader = null;

    try

    {

    string connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

    connection = new OleDbConnection(connectionString);

    connection.Open();

    //prepare sql statements

    string sql = "SELECT * from Staff where username='" + username + "'And Password='" + password + "'";

    command = new OleDbCommand(sql, connection);

    dataReader = command.ExecuteReader();

    while (dataReader.Read())

    {

    username = dataReader.GetString(3);

    Session.Add("username", username);

    }

    dataReader.Close();

    }

    catch (Exception ex)

    {

    Response.Write(ex.Message);

    }

    //cleanup object

    finally

    {

    if (connection != null)

    connection.Close();

    }

    How do I change from Oledb to SQL connection?

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply