Hi, This is an easy thing which i have done, i establish connection between SQL Server and C#.net there is a table in my database named login. My code take name and password from textbox and and password field and then check with the databse if name and passwword is correct then redirenc to a new page.
Here is the sample code:
string connectionString = “Data Source=(local);Initial Catalog=ashraftest;user id=sa;password=faisal”;
string mySelectQuery = “SELECT * from login;”;
SqlConnection myConnection = new SqlConnection(connectionString);
SqlCommand myCommand = new SqlCommand(mySelectQuery,myConnection);
myConnection.Open();
SqlDataReader myReader;
myReader = myCommand.ExecuteReader();
string s1= TextBox1.Text;
string s2= Password1.Value;
while (myReader.Read())
{
if((s1.Equals(myReader.GetString(0))) &&
(s2.Equals(myReader.GetString(1))))
Response.Redirect(“loginpage.aspx?name=”+s1);
}
myReader.Close();
myConnection.Close();
Here is the sample code:
string connectionString = “Data Source=(local);Initial Catalog=ashraftest;user id=sa;password=faisal”;
string mySelectQuery = “SELECT * from login;”;
SqlConnection myConnection = new SqlConnection(connectionString);
SqlCommand myCommand = new SqlCommand(mySelectQuery,myConnection);
myConnection.Open();
SqlDataReader myReader;
myReader = myCommand.ExecuteReader();
string s1= TextBox1.Text;
string s2= Password1.Value;
while (myReader.Read())
{
if((s1.Equals(myReader.GetString(0))) &&
(s2.Equals(myReader.GetString(1))))
Response.Redirect(“loginpage.aspx?name=”+s1);
}
myReader.Close();
myConnection.Close();
0 comments:
Post a Comment