The following code snippet allows you to browser an excel file on your machine and get data from the Excel sheet and bind one column of the Excel sheet to a ComboBox control.
The code starts by creating a connection with the Excel sheet using OleDb data provider and retrieves all data in a DataSet and binds with a DataGridView control.
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;
namespace Retrieving_excel_data_to_combobox
{
public partial class Form1 : Form
{
public OleDbConnection con;
public void pintu(string s)
{
con = new OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0; " + "data source='" + s + " '; " + "Extended Properties=Excel 8.0;");
}
public OleDbCommand com;
public DataSet ds;
public OleDbDataAdapter oledbda;
public DataTable dt;
public string str;
public Form1()
{
InitializeComponent();
}
private void btnbrowse_Click(object sender, EventArgs e)
{
OpenFileDialog openfiledialog1 = new OpenFileDialog();
openfiledialog1.ShowDialog();

Azam ShaikhPosted Jul 2, 2014, 4:14 AM
any solution?
Azam ShaikhPosted Jul 2, 2014, 4:13 AM
I want to do exactly opposite of it. i want to send an array to excel and bind it into dropdown of excel sheet