-2
using BRQ_Jobs.Modelo;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BRQ_Jobs.DAL
{
public class PesquisaDALComandos
{
string conecta = @"Integrated Security = SSPI; Persist Security Info=False;Initial Catalog = BRQ_JOBS; Data Source = NBBV027097";
SqlConnection conexao = null;
SqlCommand comando;
CadastroRecrutador recrutador = new CadastroRecrutador();
CadastroVagas vaga = new CadastroVagas();
//Método para listar os dados do banco
public DataTable Listar()
{
try
{
using (conexao = new SqlConnection(conecta))
{
if (!recrutador.Equals(vaga))
{
comando = new SqlCommand("select distinct COD_REC,NOME,SITUACAO from RECRUTADOR", conexao);
}
else if (!vaga.Equals(recrutador))
{
comando = new SqlCommand("select distinct COD_VAGA,NOME,DESCRICAO,SALARIO,SITUACAO from VAGA", conexao);
}
SqlDataAdapter da = new SqlDataAdapter();
DataTable dt = new DataTable();
da.SelectCommand = comando;
da.Fill(dt);
return dt;
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
//Método para pesquisar ao digitar
public DataTable Pesquisar(PesquisaModel pesquisa)
{
try
{
using (conexao = new SqlConnection(conecta))
{
SqlDataAdapter da = new SqlDataAdapter();
DataTable dt = new DataTable();
if (!recrutador.Equals(vaga))
{
comando = new SqlCommand("select distinct COD_REC,NOME,SITUACAO from RECRUTADOR where NOME like '%' + @nome + '%' order by NOME", conexao);
}
else if (!vaga.Equals(recrutador))
{
comando = new SqlCommand("select distinct COD_VAGA,NOME,DESCRICAO,SALARIO,SITUACAO from VAGA where NOME like '%' + @nome + '%' order by NOME", conexao);
}
comando.Parameters.AddWithValue("@nome", pesquisa.Nome);
da.SelectCommand = comando;
da.Fill(dt);
return dt;
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
conexao.Close();
}
}
}
}
First you’re doing wrong, using
SqlDataAdapterto return aDataTableis not necessary, beyond very low performance. Only your code has no way to help much, need to improve your question– novic