Marianna Gonçalves Posted April 30, 2015 at 06:57 PM Report Share #582228 Posted April 30, 2015 at 06:57 PM Boa tarde, Tenho uma procedure que puxa esses dados: SELECT TOP 100 COD_PACIENTE, NOME, RG, CPF, NUM_CARTAO, DIA_NASC, MES_NASC, ANO_NASC, IDADE, SEXO, ENDERECO, TELEFONE1, TELEFONE2, EMAIL, BAIRRO, CIDADE, NATURALIDADE, NOME_MAE, PRONTUARIO, DT_ATUALIZACAO, NOME_PAI, OCUPACAO, ESTADO_CIVIL, GRAU_INSTRUCAO, COR, RG_UF, DT_CADASTRO, USUARIO_CAD FROM [sGH]..[sYSTEM].[PACIENTES] WHERE Queria puxar todos esses dados no meu sistema filtrando pela "DT_ATUALIZAÇÃO" a data atual, como faço? Link to comment Share on other sites More sharing options...
apocsantos Posted April 30, 2015 at 07:12 PM Report Share #582231 Posted April 30, 2015 at 07:12 PM Boa tarde, Passas para dentro da procedure um parametro. static void getPacientes(string connectionString, string categoryName) { using (SqlConnection connection = new SqlConnection(connectionString)) { // Cria um comando e define as propriedades SqlCommand command = new SqlCommand(); command.Connection = connection; command.CommandText = "tuaStoredProcedure"; command.CommandType = CommandType.StoredProcedure; // Adicona o parametro e define as propriedades dele SqlParameter parameter = new SqlParameter(); parameter.ParameterName = "@DT_AGORA"; parameter.SqlDbType = SqlDbType.DateTime; parameter.Direction = ParameterDirection.Input; parameter.Value = DateTime.Now; //valor da data e hora actuais do sistema //Adiciona o parametro à colecção de parametros command.Parameters.Add(parameter); // abre a conecção e executa o reader connection.Open(); SqlDataReader reader = command.ExecuteReader(); //whatever reader.Close(); } } Provávelmente vais ter de alterar ligeiramente a tua stored procedure para suportar o parametro SELECT TOP 100 COD_PACIENTE, NOME, RG, CPF, NUM_CARTAO, DIA_NASC, MES_NASC, ANO_NASC, IDADE, SEXO, ENDERECO, TELEFONE1, TELEFONE2, EMAIL, BAIRRO, CIDADE, NATURALIDADE, NOME_MAE, PRONTUARIO, DT_ATUALIZACAO, NOME_PAI, OCUPACAO, ESTADO_CIVIL, GRAU_INSTRUCAO, COR, RG_UF, DT_CADASTRO, USUARIO_CAD FROM [sGH]..[sYSTEM].[PACIENTES] WHERE DT_ATUALIZACAO = @DT_AGORA Cordiais cumprimentos, Apocsantos "A paciência é uma das coisas que se aprendeu na era do 48k" O respeito é como a escrita de código, uma vez perdido, dificilmente se retoma o habito" Link to comment Share on other sites More sharing options...
TaoOo Posted May 30, 2015 at 05:57 PM Report Share #583985 Posted May 30, 2015 at 05:57 PM Correndo o risco de já vir muito tarde , mas mesmo assim... Não precisas de alterar o SP para receber um parametro... se esse SP usa sempre com a data actual (Hoje) então podes usar o "Getdate()" do SQL.. Apenas tens que garantir que obtens apenas a data sem a hora, pois nesse caso não deves conseguir nenhum resultado.. Algo assim: SELECT * FROM [sGH]..[sYSTEM].[PACIENTES] WHERE DT_ATUALIZACAO = CONVERT(date, getdate()) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now