So I've been working on an Application that opens any Excel file you want and can send the data to any Microsoft Access Database you want it to.
BUT I am an absolute novice at C# so I've been getting stuck a LOT. Anyways does anyone of you lovely dudes or dudettes know how to make a ComboBox drop down list from which you can select the Excel Sheet you want to see and also display it in the Gridview?
And since I'm asking for help, might as well also ask how would I make the: Send to Database button actually send the Data of the Excel Sheet to the database?
This is what the application looks like at the moment:
This is the code:
using System;
using System.Data;
using System.Data.OleDb;
using System.Windows.Forms;
namespace Data_Importer
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//Buttons
private void button1_Click(object sender, EventArgs e) //button Browse 1
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
this.textBox1.Text = openFileDialog1.FileName;
}
}
private void button2_Click(object sender, EventArgs e) //button Run
{
string PathConn = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source =" + textBox1.Text + ";Extended Properties=\"Excel 8.0;HDR=Yes;\";";
OleDbConnection conn = new OleDbConnection(PathConn);
var sqlQuery = "Select * from [Sheet1$]";
OleDbDataAdapter myDataAdapter = new OleDbDataAdapter(sqlQuery, conn);
DataTable dt = new DataTable();
myDataAdapter.Fill(dt);
dataGridView1.DataSource = dt;
}
private void button3_Click(object sender, EventArgs e) //button Browse 2
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
this.textBox2.Text = openFileDialog1.FileName;
}
}
}
}