manjula d

manjula d

  • NA
  • 172
  • 137.1k

using linq query to select count

Sep 12 2013 7:34 AM
how to write the below code using Linq query 




string str = "select Vendor_Id,UserName,count(*) from tblvendor where UserName='" + txt_UserName.Text + "'and BINARY Password='" + txt_Password.Text + "'";
 MySqlCommand cmd = new MySqlCommand(str, con);
 MySqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        VendorId = Convert.ToInt32(dr["Vendor_Id"]);
                        Session["vendorusername"] = dr["UserName"].ToString();
                        UserName = dr["UserName"].ToString();
                        Session["vusername"] = UserName;
                    }
                }
i wrote like this:
 var objUserLogin =(from objsel in objEntity.tblvendor where objsel.UserName == txt_UserName.Text && objsel.Password == txt_Password.Text select new { objsel.Vendor_Id, objsel.UserName }).Count();
if(objUserLogin > 0)
{
here table fields are not able to responding pls help me  how to get thease table fields.
}


Answers (2)