I have created one login page named login.aspx. And one database named ADMIN. I have created one table named ADMIN and in that table there are two fields ADMINISTRATOR and PASSWORD. And I have put 2-3 records in it.

When I click on login button, it should check in database that whether user is available in the database or not? and if he is available then it should go to the next page called reg.aspx else it should display an error message.

Can you please send me back code.

Here is the code:-
please mark the tread as solved if you finds this useful

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
       
    }
    protected void Button1_Click(object sender, EventArgs e)
    {//checks for validity of the values in user name and password text boxes

        ValidateUserInfo(TextBox1.Text.Trim(), TextBox2.Text.Trim());

    }

    protected void ValidateUserInfo(string user, string pass)
    {
//to establish data base connection
//put your your values for data source,initial_catalog,user_id etc

        SqlConnection connection = new SqlConnection("data source=power;initial catalog=DBS_BANK;user 

id=orange;password= orange");
        string sql = "SELECT * FROM userid WHERE username = @username AND password = @password";
        SqlCommand cmd = new SqlCommand(sql, connection);
        cmd.Parameters.AddWithValue("@username", user);
        cmd.Parameters.AddWithValue("@password", pass);
        connection.Open();

        
        SqlDataAdapter ad = new SqlDataAdapter(cmd);
        DataSet dt = new DataSet();
        ad.Fill(dt);
        if (dt.Tables[0].Rows.Count > 0)
        { //check if the query returns any data
            //Valid Username and Password
           // Response.Redirect("Default2.aspx");
            
        }
        else
        {
            Response.Write("INVALID Username and Password, Try Again!");
        }
        connection.Close();
    }
}
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

You forgot to add using System.data.sqlclient;

This article has been dead for over six months. Start a new discussion instead.