public void AddEscrito(Escrito pEscritos) { using (SqlConnection cnn = new SqlConnection(GetConnectionString())) { SqlCommand cmd = new SqlCommand(); cmd.Connection = cnn; cmd.CommandText = "INSERT INTO Escritos " + "VALUES (@Expediente, @Descripcion, @Fecha)"; cmd.Parameters.Add(new SqlParameter("@Expediente", pEscritos.Expediente)); cmd.Parameters.Add(new SqlParameter("@Descripcion", pEscritos.Descripcion)); cmd.Parameters.Add(new SqlParameter("@Fecha", pEscritos.Fecha)); cnn.Open(); cmd.ExecuteNonQuery(); } }
public List<Escrito> GetAllEscritos(int pId) { List<Escrito> listEscritos = null; using (SqlConnection cnn = new SqlConnection(GetConnectionString())) { SqlCommand cmd = new SqlCommand(); cmd.Connection = cnn; cmd.CommandText = "SELECT Id, Expediente, Descripcion " + "FROM Escritos " + "WHERE Expediente=@Expediente"; cmd.Parameters.Add(new SqlParameter("@Expediente", pId)); cnn.Open(); SqlDataReader dr = cmd.ExecuteReader(); if (dr != null && dr.HasRows) { int idIndex = dr.GetOrdinal("Id"); int expedienteIndex = dr.GetOrdinal("Expediente"); int descripcionIndex = dr.GetOrdinal("Descripcion"); listEscritos = new List<Escrito>(); while (dr.Read()) { Escrito oEscrito = new Escrito(); object[] values = new object[dr.FieldCount]; dr.GetValues(values); oEscrito.Id = (int)values[idIndex]; oEscrito.Expediente = (int)dr[expedienteIndex]; oEscrito.Descripcion = (string)dr[descripcionIndex]; listEscritos.Add(oEscrito); } } } return listEscritos; }
public static void agregarEscrito(Escrito pEscrito) { DataAccessLayerExpediente oDAL = new SQLExpediente(); oDAL.AddEscrito(pEscrito); }