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;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            string connectionString;
            connectionString =("Data Source=INTRANETSERVER1;User ID=sa;Initial Catalog=HrData");
            SqlConnection myConnection = new SqlConnection(connectionString);
            SqlDataAdapter ad = new SqlDataAdapter("SELECT * FROM BMauthority1", myConnection);
            DataSet ds = new DataSet();
            ad.Fill(ds,"pwd");
            GridView1.DataSource = ds;
            GridView1.DataBind();
        } 
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            string uname = TextBox1.Text; //Get the username from the control
            string password = TextBox2.Text; //get the Password from the control
            bool flag = AuthenticateUser(uname, password);
            if (flag == true)
            {
                Response.Write("Successfult login");
                Response.Redirect("Default2.aspx"); 
            }
        }
        catch (Exception)
        {
            Response.Write("Incorrect user name or password"); 
        }
    }
   private bool AuthenticateUser(string uname, string password)
    {  
        bool bflag = false;
        string connectionString;
        connectionString = ("Data Source=INTRANETSERVER1;User ID=sa;Initial Catalog=HrData");
        SqlConnection myConnection = new SqlConnection(connectionString);
        SqlDataAdapter ad = new SqlDataAdapter("SELECT * FROM BMauthority1", myConnection);
        DataSet ds = new DataSet();
        ad.Fill(ds);
        if (ds != null)
        {
         if( == TextBox1.Text )
          {
              bflag = true;
          }
        }
      return bflag;
    }
}

i want to check database column value with textbox1 then,
what should i write in if condition?

u can write it as
ds.rows[0]["columnname"].tostring();

>>how to check database column value with textbox?

Answer is "SELECT with WHERE clause".

string connectionString;
connectionString =("Data Source=INTRANETSERVER1;User ID=sa;Initial Catalog=HrData");
SqlConnection myConnection = new SqlConnection(connectionString);
SqlCommand cmd=new SqlCommand();
cmd.CommandText="SELECT * FROM BMauthority1 where columnName=@p1";
cmd.Connection=myConnection;

cmd.Parameters.AddWithValue("@p1",TextBox1.Text);

myConnection.Open();
object result=cmd.ExecuteScalar();
myConnection.Close();

if(result==null)
   {
    // not found
    }
else
  {

   // found
  }
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;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            string connectionString;
            connectionString =("Data Source=INTRANETSERVER1;User ID=sa;Initial Catalog=HrData");
            SqlConnection myConnection = new SqlConnection(connectionString);
            SqlDataAdapter ad = new SqlDataAdapter("SELECT * FROM BMauthority1", myConnection);
            DataSet ds = new DataSet();
            ad.Fill(ds,"pwd");
           
        } 
    }
    
   private bool AuthenticateUser(string uname, string password)
    {  
        bool bflag = false;
        string connectionString;
        connectionString = ("Data Source=INTRANETSERVER1;User ID=sa;Initial Catalog=HrData");
        SqlConnection myConnection = new SqlConnection(connectionString);
        SqlDataAdapter ad = new SqlDataAdapter("SELECT * FROM BMauthority1 where BMID ='"+ TextBox1.Text +"' and pwd ='"+ TextBox2.Text +"' ", myConnection);
        DataSet ds = new DataSet();
        ad.Fill(ds);
        if (ds != null)
        {
          bflag = true;
        }
      return bflag;
    }
    protected void Button1_Click1(object sender, EventArgs e)
    {
        try
        {
            string uname = TextBox1.Text; //Get the username from the control
            string password = TextBox2.Text; //get the Password from the control
            bool flag = AuthenticateUser(uname, password);
            if (flag == true)
            {
                Response.Write("Successfult login");
                Response.Redirect("Default2.aspx");
            }
        }
        catch (Exception)
        {
            Response.Write("Incorrect user name or password");
        }

    }
}

i have written above code & its working.
Thanks to all

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.