witam,
tworzę prostą aplikację mającą możliwość importu danych bezpośrednio z plików Excel z wykorzystaniem wzorca singleton, i napotkałem problem, pojawia się błąd "Zewnętrzna tabela nie ma oczekiwanego formatu" przy connection.Open()
Czy mógłby ktoś podpowiedzieć dlaczego otrzymuje taki błąd? i od razu sprawdzić poprawność zastosowania wzorca
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.IO;
namespace database
{
public partial class Form1 : Form
{
public sealed class Singleton
{
public OleDbConnection connection;
private static volatile Singleton instance;
private static object syncRoot = new Object();
private Singleton()
{
StreamReader xlsxFilename = new StreamReader("C://test.xlsx");
//Podłączenie dla Excela 2007
connection = new OleDbConnection(String.Format(@"Provider= Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=""Excel 12.0;HDR=YES;""", xlsxFilename));
}
public void Open()
{
connection.Open();
}
public void Close()
{
connection.Close();
}
public static Singleton Instance
{
get
{
if (instance == null)
{
lock (syncRoot)
{
if (instance == null)
instance = new Singleton();
}
}
return instance;
}
}
}
public Form1()
{
InitializeComponent();
}
private void btSearch_Click(object sender, EventArgs e)
{
List<string> list = new List<string>();
Singleton con = Singleton.Instance;
string queryString = "select * from [Arkusz1$]";
OleDbCommand command = new OleDbCommand(queryString, con.connection);
con.Open();
OleDbDataReader reader = command.ExecuteReader();
while (reader.Read())
list.Add(reader[0].ToString());
}
}
}
dzięki za odp