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();
}
}
}
views:
44answers:
1
+2
A:
There is a lot wrong with that code.
- Selecting everything from the users table, instead of filtering using a WHERE clause
- Looping over all tables in the dataset - only 1 is returned
- Checking for empty textboxes, but allowing any amount of whitespace to be accepted
- Txtspk in user messages.
Jamiec
2010-08-02 07:50:22
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
2010-08-02 07:56:47
hi thanks i got the solution n how can i give a link to button in asp.net
santhosh s samaka
2010-08-02 07:59:04
that would be a new question
CodeSlave
2010-08-03 03:13:09