Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 89273

How to insert Excel Data into existing table in C#

$
0
0

Hi so I've only just began creating a exam scheduling system and I have an issue when inserting a Excel table into my data grid view. I've created some rows and columns for time however when i insert new data it pads with empty cells and inserts below instead of going into the existing ones. Any help is appreciated.

string PathConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + txtPath.Text + ";Extended Properties=\"Excel 8.0; HDR = Yes;\";";

OleDbConnection MyConnection = new OleDbConnection(PathConn);
OleDbDataAdapter myDataAdapter = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", MyConnection);
DataTable dt = new DataTable();            
dt.Columns.Add("Time");

DataRow dr = dt.NewRow();
dr["Time"] = "9:00";
dt.Rows.Add(dr);

DataRow dr1 = dt.NewRow();
dr1["Time"] = "10:00";
dt.Rows.Add(dr1);

`etc`

myDataAdapter.Fill(dt);            
DataGridView1.DataSource = dt;

Viewing all articles
Browse latest Browse all 89273

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>