public tpeople GetPeople(int people) { SqlConnection con = new SqlConnection(connectionString); SqlCommand cmd = new SqlCommand("GetPeople", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@peopleID", SqlDbType.Int, 4)); cmd.Parameters["@peopleID"].Value = people; // Создать коллекцию для всех записей tpeople emp2 = new tpeople(); try { con.Open(); SqlDataReader reader = cmd.ExecuteReader(); emp2.Fio = (string)reader["Fio"]; emp2.FioLat=(string)reader["FioLat"]; emp2.Sex=(string)reader["Sex"]; emp2.Address=(string)reader["Address"]; emp2.Email=(string)reader["Email"]; emp2.Phone= (string)reader["Phone"]; emp2.Birthday=(string)reader["Birthday"]; emp2.Seriapasp=(string)reader["Seriapasp"]; emp2.Numberpasp = (string)reader["Numberpasp"]; emp2.Whopasp=(string)reader["Whopasp"]; emp2.Wherepasp=(string)reader["Wherepasp"]; emp2.Seriazpasp = (string)reader["Seriazpasp"]; emp2.Numberzpasp=(string)reader["Numberzpasp"]; emp2.Whozpasp=(string)reader["Whozpasp"]; emp2.Wherezpasp=(string)reader["Wherezpasp"]; emp2.Wherendzpasp=(string)reader["Wherendzpasp"]; reader.Close(); return emp2; } catch { throw new ApplicationException("Ошибка данныx!"); } finally { con.Close(); } }
public int Insertpeople(tpeople emp1) { SqlConnection con = new SqlConnection(connectionString); SqlCommand cmd = new SqlCommand("Insertpeople", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@Fio", SqlDbType.NVarChar, 150)); cmd.Parameters["@Fio"].Value = emp1.Fio; cmd.Parameters.Add(new SqlParameter("@FioLat", SqlDbType.NVarChar, 150)); cmd.Parameters["@FioLat"].Value = emp1.FioLat; cmd.Parameters.Add(new SqlParameter("@Sex", SqlDbType.NVarChar,1)); cmd.Parameters["@Sex"].Value = emp1.Sex; cmd.Parameters.Add(new SqlParameter("@Address", SqlDbType.NVarChar, 200)); cmd.Parameters["@Address"].Value = emp1.Address; cmd.Parameters.Add(new SqlParameter("@Email", SqlDbType.NVarChar, 50)); cmd.Parameters["@Email"].Value = emp1.Email; cmd.Parameters.Add(new SqlParameter("@Phone", SqlDbType.NVarChar, 20)); cmd.Parameters["@Phone"].Value = emp1.Phone; cmd.Parameters.Add(new SqlParameter("@Birthday", SqlDbType.NVarChar, 10)); cmd.Parameters["@Birthday"].Value = emp1.Birthday; cmd.Parameters.Add(new SqlParameter("@Seriapasp", SqlDbType.NVarChar, 10)); cmd.Parameters["@Seriapasp"].Value = emp1.Seriapasp; cmd.Parameters.Add(new SqlParameter("@Seriazpasp", SqlDbType.NVarChar, 10)); cmd.Parameters["@Seriazpasp"].Value = emp1.Seriazpasp; cmd.Parameters.Add(new SqlParameter("@Numberpasp", SqlDbType.NVarChar, 10)); cmd.Parameters["@Numberpasp"].Value = emp1.Numberpasp; cmd.Parameters.Add(new SqlParameter("@Numberzpasp", SqlDbType.NVarChar, 10)); cmd.Parameters["@Numberzpasp"].Value = emp1.Numberzpasp; cmd.Parameters.Add(new SqlParameter("@Whopasp", SqlDbType.NVarChar, 150)); cmd.Parameters["@Whopasp"].Value = emp1.Whopasp; cmd.Parameters.Add(new SqlParameter("@Whozpasp", SqlDbType.NVarChar, 150)); cmd.Parameters["@Whozpasp"].Value = emp1.Whozpasp; cmd.Parameters.Add(new SqlParameter("@Wherepasp", SqlDbType.NVarChar, 10)); cmd.Parameters["@Wherepasp"].Value = emp1.Wherepasp; cmd.Parameters.Add(new SqlParameter("@Wherezpasp", SqlDbType.NVarChar, 10)); cmd.Parameters["@Wherezpasp"].Value = emp1.Wherezpasp; cmd.Parameters.Add(new SqlParameter("@Wherendzpasp", SqlDbType.NVarChar, 10)); cmd.Parameters["@Wherendzpasp"].Value = emp1.Wherendzpasp; cmd.Parameters.Add(new SqlParameter("@peopleID", SqlDbType.Int, 6)); cmd.Parameters["@peopleID"].Direction = ParameterDirection.Output; try { con.Open(); cmd.ExecuteNonQuery(); return (int)cmd.Parameters["@peopleID"].Value; } catch { throw new ApplicationException("Ошибка данныx. добавление физ лица"); } finally { con.Close(); } }
public List<tpeople> GetAllPeoples() { SqlConnection con = new SqlConnection(connectionString); SqlCommand cmd = new SqlCommand("GetAllPeoples", con); cmd.CommandType = CommandType.StoredProcedure; // Создать коллекцию для всех записей List<tpeople> Peoples = new List<tpeople>(); //tpeople emp2 = new tpeople(0,"","","","","","","","","","","","","","","",""); //Peoples.Add(emp2); try { con.Open(); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { tpeople emp = new tpeople( (int)reader["peopleID"], (string)reader["Fio"], (string)reader["FioLat"], (string)reader["Sex"], (string)reader["Address"], (string)reader["Email"], (string)reader["Phone"], (string)reader["Birthday"], (string)reader["Seriapasp"], (string)reader["Numberpasp"], (string)reader["Whopasp"], (string)reader["Wherepasp"], (string)reader["Seriazpasp"], (string)reader["Numberzpasp"], (string)reader["Whozpasp"], (string)reader["Wherezpasp"], (string)reader["Wherendzpasp"]); Peoples.Add(emp); } reader.Close(); return Peoples; } catch { throw new ApplicationException("Ошибка данныx!"); } finally { con.Close(); } }