-
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();
-
August 26th, 2009, 06:58 AM
#2
Re: excel & oledb insert
excume me
i'v resolved problem with xlsx file...with this connection string
baglanti = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=\"Excel 12.0 xml;HDR=YES;\"");
but warn about "Number stored as text" still persist...
-
August 26th, 2009, 03:05 PM
#3
-
August 26th, 2009, 04:35 PM
#4
Re: excel & oledb insert
I'v tried that but same problem exist...
I found that setting IMEX=1 in connection string will resolved this problem....but this leads to
"file doesnot exist" error...
is there a way to create a new excel file by oledb when setting IMEX=1?
i tried creating excel file using ExcelApplication...but this leads to incompatibility with above code
and doesnt work too...
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
|