.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Visual Studio >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Retrieving Excel Data To combobox

Posted By:satyapriyanayak       Posted Date: July 02, 2013    Points: 40    Category: Visual Studio    URL: http://www.dotnetspark.com  

Retrieving Excel Data To combobox
 

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();

            openfiledialog1.Filter = "allfiles|*.xls";

            TextBox1.Text = openfiledialog1.FileName;

 

        }

 

        private void Form1_Load(object sender, EventArgs e)

        {

            comboBox1.Text = "Please select";

        }

 

        private void btndisplay_Click(object sender, EventArgs e)

        {

            pintu(TextBox1.Text);

            try

            {

                con.Open();

                str = "select * from [sheet1$]";

                com = new OleDbCommand(str, con);

                ds = new DataSet();

                oledbda = new OleDbDataAdapter(com);

                oledbda.Fill(ds, "[sheet1$]");

                con.Close();

                DataGridView1.DataSource = ds;

                DataGridView1.DataMember = "[sheet1$]";

            }

            catch (Exception ex)

            {

                MessageBox.Show(ex.Message);

            }

 

 

            try

        &a



     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend