SELECT QUERY WITH AND CONDITION

jacob rasel

Total Post:88

Points:616
Posted by  jacob rasel
 760  View(s)
Ratings:
Rate this:

I want to select user but i cant get it . Here's my query

 

        SqlCommand myCommand = new SqlCommand("Select * from Users where Email=" + UserEmailPass.Email + "And Password=" + UserEmailPass.Password, conn);

        SqlDataReader Detailsreader = myCommand.ExecuteReader();

Is my query correct or not>? please help

  1. Kamlakar Singh

    Post:194

    Points:1396
    Re: select Query with AND Condition

    SqlCommand myCommand = new SqlCommand("Select * from Users where Email=@mail and Password@pass" , conn);

    System.Data.SqlClient.SqlParameter par = new System.Data.SqlClient.SqlParameter("@mail",  UserEmailPass.Email );

    System.Data.SqlClient.SqlParameter par1 = new System.Data.SqlClient.SqlParameter("@pass", UserEmailPass.Password);

           myCommand.Parameters.Add(par);

           myCommand.Parameters.Add(par1);

            SqlDataReader Detailsreader = myCommand.ExecuteReader();

    DO NOT USE string concat!!!!

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!