Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Olá,
Tenho uma banco access e preciso fazer um select que me traga algums campos e mostre num gridview. Vejam abaixo o select:
OleDbConnection aCONN = new OleDbConnection(ConfigurationManager.ConnectionStrings["dbAccess"].ToString());
string DataInicial = txtDataInicial.Text.Substring(3, 2) + "/" + txtDataInicial.Text.Substring(0, 2) + "/" +
txtDataInicial.Text.Substring(6, 4);
string DataFinal = txtDataFinal.Text.Substring(3, 2) + "/" + txtDataFinal.Text.Substring(0, 2) + "/" +
txtDataFinal.Text.Substring(6, 4);
string strSelect = "select tabSacado.ssacaCodSacado, tabSacado.ssacaNome, tabTitulos.ttituDtDoc, tabTitulos.ttituDtVcto, " +
"tabTitulos.dtituValDoc, tabTitulos.ttituDtOco, tabTitulos.dtituValPgto, tabTitulos.stituNossoNum " +
"from tabTitulos ";
string strInnerJoin = "inner join tabSacado on tabTitulos.ssacaCodSacado = tabSacado.ssacaCodSacado ";
string strWhere = null;
if ((txtDataInicial.Text != "__/__/____") && (txtDataFinal.Text != "__/__/____"))
{
strWhere = "where (((tabTitulos.ttituDtDoc) between #" + DataInicial + "# and #" + DataFinal + "#) and " +
"((tabTitulos.dtituValPgto)=0) and ((tabTitulos.ttituDtOco) is null))";
}
else
{
strWhere = "where ((tabTitulos.dtituValPgto)=0) and ((tabTitulos.ttituDtOco) is null)";
}
string strConsulta = null;
strConsulta = strSelect + strInnerJoin + strWhere + " order by tabSacado.ssacaNome, tabTitulos.ttituDtDoc;";
OleDbCommand cmdSQL = new OleDbCommand(strConsulta, aCONN);
aCONN.Open();
OleDbDataAdapter da = new OleDbDataAdapter(cmdSQL);
DataTable dbDados = new DataTable();
da.Fill(dbDados);
grdFaturamento.DataSource = dbDados;
grdFaturamento.DataBind();
Quando rodo o select com a data inicial: 20/08/2010 e data final: 24/08/2010 ele exibe no gridview, somente os registros de data(ttituDtDoc) = 20/08/2010 sendo que no banco, tem datas no período 20/08/2010 a 24/08/2010.
Obs.: Se eu pegar esse códiog e rodar direto em uma colsulta dentro do banco, funciona.
Alguém ajuda ?????
Obrigado.
Carregando comentários...