Change your code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OleDb;
using Excel = Microsoft.Office.Interop.Excel;
using System.IO;
using System.Collections;
namespace ConsoleApplication36
{
class Program
{
public static OleDbDataAdapter CreateCustomerAdapter(OleDbConnection connection)
{
OleDbDataAdapter adapter = new OleDbDataAdapter();
OleDbCommand command;
command = new OleDbCommand("SELECT * FROM Customers " +
"WHERE Country = ? AND City = ?", connection);
command.Parameters.Add("Country", OleDbType.VarChar, 15);
command.Parameters.Add("City", OleDbType.VarChar, 15);
adapter.SelectCommand = command;
command = new OleDbCommand(
"INSERT INTO Customers (CustomerID, CompanyName) " +
"VALUES (?, ?)", connection);
command.Parameters.Add(
"CustomerID", OleDbType.Char, 5, "CustomerID");
command.Parameters.Add(
"CompanyName", OleDbType.VarChar, 40, "CompanyName");
adapter.InsertCommand = command;
return adapter;
}
static void Main()
{
var p = new Program();
p.Bar();
}
void Bar()
{
DataTable t = new DataTable();
OleDbConnection connection = null;
OleDbDataAdapter adapter1 = new OleDbDataAdapter();
adapter1 = CreateCustomerAdapter(connection);
adapter1.Fill(t);
PrintDataTable(t);
Console.ReadKey();
}
void PrintDataTable(DataTable dt)
{
foreach (DataRow row in dt.Rows)
{
Console.WriteLine();
for(int x = 0; x < dt.Columns.Count; x++)
{
Console.Write(row[x].ToString() + " | ");
}
}
}
}
}