public NotaEntrada GetById(long id) { NotaEntrada notaEntrada = new NotaEntrada(); DAL_Fornecedor dalFornecedor = new DAL_Fornecedor(); long idFornecedorNota = -1; var command = new SqlCommand("select id, idfornecedor, numero, dataemissao, dataentrada from NOTASDEENTRADA where id = @id", connection); command.Parameters.AddWithValue("@id", id); connection.Open(); using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { var teste = reader[1]; notaEntrada.Id = reader.GetInt64(0); idFornecedorNota = reader.GetInt64(1); notaEntrada.Numero = reader.GetString(2); notaEntrada.DataEmissao = reader.GetDateTime(3); notaEntrada.DataEntrada = reader.GetDateTime(4); } } connection.Close(); if (idFornecedorNota > 0) { notaEntrada.FornecedorNota = dalFornecedor.GetById(idFornecedorNota); } return(notaEntrada); }