public cls_operations_admin select_Profile(string fName) { cls_conection obj1 = new cls_conection(); cls_operations_admin matchingPerson = new cls_operations_admin(0, "", "", "", "", "", "", ""); using (SqlConnection myConnection = new SqlConnection(obj1.getConnection())) { string oString = "SELECT first_name,last_name,number_phone,country,city,address,zip_code FROM Data_Admin WHERE FK_ID_admin=@fName"; SqlCommand oCmd = new SqlCommand(oString, myConnection); oCmd.Parameters.AddWithValue("@fname", fName); myConnection.Open(); using (SqlDataReader oReader = oCmd.ExecuteReader()) { while (oReader.Read()) { //I got problem getting the PRIMARY KEY and the FOREIGN KEY //matchingPerson.Fk_id_cat = Int32.Parse(oReader["ID_prod"].ToString()); matchingPerson.First_Name = oReader["first_name"].ToString(); matchingPerson.Last_Name = oReader["last_name"].ToString(); matchingPerson.Number_Phone = oReader["number_phone"].ToString(); matchingPerson.Country = oReader["country"].ToString(); matchingPerson.City = oReader["city"].ToString(); matchingPerson.Address = oReader["address"].ToString(); matchingPerson.Zip_Code = oReader["zip_code"].ToString(); } myConnection.Close(); } } return(matchingPerson); }
public cls_operations_admin Select(string fName) { cls_conection obj1 = new cls_conection(); cls_operations_admin matchingPerson = new cls_operations_admin(); using (SqlConnection myConnection = new SqlConnection(obj1.getConnection())) { string oString = "Select name,brand,price,description,photo,current_stock from Products where ID_prod=@fName"; SqlCommand oCmd = new SqlCommand(oString, myConnection); oCmd.Parameters.AddWithValue("@fname", fName); myConnection.Open(); using (SqlDataReader oReader = oCmd.ExecuteReader()) { while (oReader.Read()) { //I got problem getting the PRIMARY KEY and the FOREIGN KEY //matchingPerson.Fk_id_cat = Int32.Parse(oReader["ID_prod"].ToString()); matchingPerson.Name = oReader["name"].ToString(); matchingPerson.Brand = oReader["brand"].ToString(); matchingPerson.Price = float.Parse(oReader["price"].ToString()); matchingPerson.Description = oReader["description"].ToString(); matchingPerson.Photo = oReader["photo"].ToString(); matchingPerson.Current_stock = Int32.Parse(oReader["current_stock"].ToString()); } myConnection.Close(); } } return(matchingPerson); }