Tuesday, October 14, 2008

Sql Databse Connection in asp.net

//This code create a sql connection and checks for the username and password
SqlConnection con = new SqlConnection(SqlDataSource1 .ConnectionString.ToString());
con.Open();
SqlDataAdapter ada = new SqlDataAdapter("Select * from login",con);
DataSet ds = new DataSet();
ada.Fill(ds,"login");
int len = ds.Tables[0].Rows.Count;
DataRow dr;
for (int i = 0; i < len; i++)
{
dr = ds.Tables[0].Rows[i];
if (s.Equals(dr[0].ToString()) && pass.Equals(dr[1].ToString()))
{
Response.Redirect("Home.aspx?user="+s);
}

}
Response.Redirect("Login.aspx");

con.Close();

No comments: