J
Jan Agermose
Im writing information into an existing excel document using a connection
string like:
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Filename +
";Extended Properties=\"Excel 8.0;HDR=yes;\"";
and one of to methods for inserting data. First I simply tried building
insert statements as strings
"insert into [Ark1$] ([MyText], [MyInt]) values ('Some text', 42)"
And I also tried
com = OleDbCommand(insert into [Ark1$] ([MyText], [MyInt]) values (?,?));
com.Parameters.Add("@MyText", OleDbType.VarChar).Value = "test";
com.Parameters.Add("@MyText", OleDbType.Int).Value = 42;
Now both methods do insert the values into the excel, but there is one very
big problem. When you open the excel document, the int values are inserted
as text! Excel markes the column with an warrning and this allowes you to
convert the "text" into prober integer values. The real problem is, that if
you fail to make this conversion, and enter/alter data in the "int-column"
you will be unable to load the excel data using an OleDbCommand("select *
from [Ark1$]");
Does anyone know a solution - or a nother newgroup to post to, if this is
not the place?
Jan Agermose
string like:
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Filename +
";Extended Properties=\"Excel 8.0;HDR=yes;\"";
and one of to methods for inserting data. First I simply tried building
insert statements as strings
"insert into [Ark1$] ([MyText], [MyInt]) values ('Some text', 42)"
And I also tried
com = OleDbCommand(insert into [Ark1$] ([MyText], [MyInt]) values (?,?));
com.Parameters.Add("@MyText", OleDbType.VarChar).Value = "test";
com.Parameters.Add("@MyText", OleDbType.Int).Value = 42;
Now both methods do insert the values into the excel, but there is one very
big problem. When you open the excel document, the int values are inserted
as text! Excel markes the column with an warrning and this allowes you to
convert the "text" into prober integer values. The real problem is, that if
you fail to make this conversion, and enter/alter data in the "int-column"
you will be unable to load the excel data using an OleDbCommand("select *
from [Ark1$]");
Does anyone know a solution - or a nother newgroup to post to, if this is
not the place?
Jan Agermose