|
-
August 26th, 2009, 06:37 AM
#1
excel & oledb insert
I'v write the following code to insert into excel 2007 file, but excel doesn't open *.xlsx file....
after that i change file extension to *.xls ...exel opens file...but warn about "Number stored as text" for all my data....
OleDbConnection baglanti = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Excel 12.0;HDR=YES;");
baglanti.Open();
string createTableScript = "CREATE TABLE newTable(a1 INT,a2 INT,a3 INT)";
OleDbCommand cmd = new OleDbCommand(createTableScript, baglanti);
cmd.ExecuteNonQuery();
.
.
.
string insertScript = "insert into [newTable$] (a1,a2,a3) values (" + (i + 1).ToString() + "," + (j + 1).ToString() + "," + ((int)p).ToString() + ")";
cmd = new OleDbCommand(insertScript, baglanti);
cmd.ExecuteNonQuery();
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|