-1
I need to use data from a specific column in a file .MDB
. I can read the file, but it only shows me first column, I tried to change the SELECT
, changing the * by column name, but it didn’t work out
Reference: code of the http://www.macoratti.net/Default.aspx
using System;
using System.Collections.Generic;
using System.Data.OleDb;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AcessoMDB
{
class Program
{
static void Main(string[] args)
{
//cria a conexão com o banco de dados
OleDbConnection aConnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\c066408\Desktop\Sprint\68\16417\BEC.MZ.BEX0.R007T.D0220.P0724.AL\BEC.MZ.BEX0.R007T.D0220.P0724.AL.mdb");
//cria o objeto command and armazena a consulta SQL
OleDbCommand aCommand = new OleDbCommand("select * from SysTable", aConnection);
try
{
aConnection.Open();
//cria o objeto datareader para fazer a conexao com a tabela
OleDbDataReader aReader = aCommand.ExecuteReader();
Console.WriteLine("Os valores retornados da tabela são : ");
//Faz a interação com o banco de dados lendo os dados da tabela
while(aReader.Read())
{
Console.WriteLine(aReader.GetString(1));
}
//fecha o reader
aReader.Close();
//fecha a conexao
aConnection.Close();
//pausa
Console.ReadLine();
}
//Trata a exceção
catch(OleDbException e)
{
Console.WriteLine("Error: {0}", e.Errors[0].Message);
}
}
}
}
What didn’t work out?
– novic