using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.OleDb;
using excel = Microsoft.Office.Interop.Excel;
namespace uygulama
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void göster_Click(object sender, EventArgs e)
{
OleDbConnectionStringBuilder excelAyar = new OleDbConnectionStringBuilder();
excelAyar.DataSource = @\"C:\\wonderkidList.xlsx\";
excelAyar.Provider = \"Microsoft.ACE.OLEDB.12.0\";
excelAyar[\"Extended Properties\"] = \"Excel 12.0 Xml;HDR=YES\";
string excelSayfaAdi = \"Sayfa1\";
OleDbConnection baglanti = new OleDbConnection(excelAyar.ConnectionString); baglanti.Open(); OleDbDataAdapter adap = new OleDbDataAdapter(\"SELECT * FROM [\" + excelSayfaAdi + \"$]\", baglanti);
DataTable dt = new DataTable(); adap.Fill(dt);
dataGridView1.DataSource = dt;
}
}
}
Buyrun hocam
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.OleDb;
using excel = Microsoft.Office.Interop.Excel;
namespace uygulama
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void göster_Click(object sender, EventArgs e)
{
OleDbConnectionStringBuilder excelAyar = new OleDbConnectionStringBuilder();
excelAyar.DataSource = @\"C:\\wonderkidList.xlsx\";
excelAyar.Provider = \"Microsoft.ACE.OLEDB.12.0\";
excelAyar[\"Extended Properties\"] = \"Excel 12.0 Xml;HDR=YES\";
string excelSayfaAdi = \"Sayfa1\";
OleDbConnection baglanti = new OleDbConnection(excelAyar.ConnectionString); baglanti.Open(); OleDbDataAdapter adap = new OleDbDataAdapter(\"SELECT * FROM [\" + excelSayfaAdi + \"$]\", baglanti);
DataTable dt = new DataTable(); adap.Fill(dt);
dataGridView1.DataSource = dt;
}
}
}
merhabalar. excel de olan verileri visual üzerinden bi programda toplamak istiyorum. internetten bakıp yaptığım kadarıyla her şey sorunsuz fakat butona bastıktan sonra
" OLEDBException was unhandled" hatası alıyorum.
baglanti.open(); kısmında hatayı veriyor. sizce nasıl çözebilirim bu hatayı ?
hakan 10 yıl önce
Kodlary paylaşabilir misiniz?
Toplam 2 cevap
Tolga Merhaba,
OLEDBException was unhandled hatası genelde Excel kolon adlarını yanlış yazdığında, SQL sorgusunda hata varsa olur.
Kodları bizimle sorunun içinde paylaşırsan yardımcı olabiliriz.
Buyrun hocam
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.OleDb;
using excel = Microsoft.Office.Interop.Excel;
namespace uygulama
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void göster_Click(object sender, EventArgs e)
{
OleDbConnectionStringBuilder excelAyar = new OleDbConnectionStringBuilder();
excelAyar.DataSource = @"C:\wonderkidList.xlsx";
excelAyar.Provider = "Microsoft.ACE.OLEDB.12.0";
excelAyar["Extended Properties"] = "Excel 12.0 Xml;HDR=YES";
string excelSayfaAdi = "Sayfa1";
OleDbConnection baglanti = new OleDbConnection(excelAyar.ConnectionString); baglanti.Open(); OleDbDataAdapter adap = new OleDbDataAdapter("SELECT * FROM [" + excelSayfaAdi + "$]", baglanti);
DataTable dt = new DataTable(); adap.Fill(dt);
dataGridView1.DataSource = dt;
}
}
}