public t_baza GetTur(int turid) { SqlConnection con = new SqlConnection(connectionString); SqlCommand cmd = new SqlCommand("GetTur", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@turid", SqlDbType.Int, 6)); cmd.Parameters["@turid"].Value = turid; t_baza t_bazas = new t_baza(); try { con.Open(); SqlDataReader reader = cmd.ExecuteReader(); t_bazas.T_bazaID = turid; t_bazas.Name = (string)reader["name"]; t_bazas.Way = (string)reader["way"]; t_bazas.Address = (string)reader["address"]; t_bazas.Email = (string)reader["email"]; t_bazas.Phone = (string)reader["phone"]; t_bazas.Siteurl = (string)reader["siteurl"]; t_bazas.About = (string)reader["about"]; t_bazas.Fio = (string)reader["fio"]; t_bazas.Dolgn = (string)reader["dolgn"]; t_bazas.Agent = (int)reader["agent"]; reader.Close(); return t_bazas; } catch { throw new ApplicationException("Ошибка данныx."); } finally { con.Close(); } }
/* Спойлер * * */ public int InsertTur(t_baza emp1) { SqlConnection con = new SqlConnection(connectionString); SqlCommand cmd = new SqlCommand("InsertTur", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@name", SqlDbType.NVarChar, 150)); cmd.Parameters["@name"].Value = emp1.Name; cmd.Parameters.Add(new SqlParameter("@way", SqlDbType.NVarChar, 200)); cmd.Parameters["@way"].Value = emp1.Way; 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("@siteurl", SqlDbType.NVarChar, 50)); cmd.Parameters["@siteurl"].Value = emp1.Siteurl; cmd.Parameters.Add(new SqlParameter("@about", SqlDbType.NVarChar, 200)); cmd.Parameters["@about"].Value = emp1.About; cmd.Parameters.Add(new SqlParameter("@fio", SqlDbType.NVarChar, 150)); cmd.Parameters["@fio"].Value = emp1.About; cmd.Parameters.Add(new SqlParameter("@dolgn", SqlDbType.NVarChar, 50)); cmd.Parameters["@dolgn"].Value = emp1.About; cmd.Parameters.Add(new SqlParameter("@agent", SqlDbType.Int, 3)); cmd.Parameters["@agent"].Value = emp1.Agent; cmd.Parameters.Add(new SqlParameter("@t_bazaID", SqlDbType.Int, 6)); cmd.Parameters["@t_bazaID"].Direction = ParameterDirection.Output; try { con.Open(); cmd.ExecuteNonQuery(); return (int)cmd.Parameters["@t_bazaID"].Value; } catch { return 0; throw new ApplicationException("Ошибка данныx."); } finally { con.Close(); } }
public List<t_baza> GetAllTurs() { SqlConnection con = new SqlConnection(connectionString); SqlCommand cmd = new SqlCommand("GetAllTurs", con); cmd.CommandType = CommandType.StoredProcedure; // Создать коллекцию для всех записей List<t_baza> t_bazas = new List<t_baza>(); t_baza b = new t_baza(0, "", "", "", "", "", "", "","","", 0); try { con.Open(); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { t_baza emp = new t_baza( (int)reader["t_bazaID"], (string)reader["name"], (string)reader["way"], (string)reader["address"], (string)reader["email"], (string)reader["phone"], (string)reader["siteurl"], (string)reader["about"], (string)reader["fio"], (string)reader["dolgn"], (int)reader["agent"]); t_bazas.Add(emp); } reader.Close(); return t_bazas; } catch { throw new ApplicationException("Ошибка данныx."); } finally { con.Close(); } }