tags:

views:

44

answers:

1
public partial class _Default : System.Web.UI.Page 
{
    protected void Button1_Click(object sender, EventArgs e)
    {    
        if (TextBox1.Text == "" && TextBox2.Text == "" || TextBox1.Text == "")
        {    
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "LoggedInScript", "alert('Plz Specify Username And Password'); window.location = 'Default.aspx';", true);                
        }

        else if (TextBox2.Text == "")
        {
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "LoggedInScript", "alert('plz Specify Password'); window.location = 'Default.aspx';", true);                
        }
        else
        {
            string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Samples\\login.mdb";

            OleDbConnection myConnection = new OleDbConnection(connectionString);
            myConnection.Open();

            string query1 = "select * from LOGIN_TABLE";

            OleDbDataAdapter myAdapter = new OleDbDataAdapter(query1, myConnection);
            DataSet loginData = new DataSet();
            myAdapter.Fill(loginData);    

            foreach (DataTable table in loginData.Tables)
            {    
                foreach (DataRow row in table.Rows)
                {                        
                    if (TextBox1.Text == row["UserName"].ToString() && TextBox2.Text == row["Password"].ToString())
                    {
                        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "LoggedInScript", "alert('Login SucessFull'); window.location = 'Default.aspx';", true);
                        break;
                    }
                    else
                    {
                        {
                            String a = TextBox1.Text;
                            String b = row["UserName"].ToString();
                            Response.Write(a);
                            Response.Write(b);
                            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "LoggedInScript", "alert('Login Failed'); window.location = 'Default.aspx';", true);
                            break;
                        }
                    }
                }
            }
            myConnection.Close();
        }            
    }
}
+2  A: 

There is a lot wrong with that code.

  1. Selecting everything from the users table, instead of filtering using a WHERE clause
  2. Looping over all tables in the dataset - only 1 is returned
  3. Checking for empty textboxes, but allowing any amount of whitespace to be accepted
  4. Txtspk in user messages.
Jamiec
they shouldnt need to loop at all, if they had listed filters such as the username (item 1) then they wouldnt need to loop (item 2) as 0 rows = no user and 1 row = user found.
Mauro
hi thanks i got the solution n how can i give a link to button in asp.net
santhosh s samaka
that would be a new question
CodeSlave