Shaitan00 Posted September 24, 2005 Posted September 24, 2005 Really odd problem - I am trying to add an integer value to a cell in Excel using the following statement: "INSERT INTO [Task$] ([CLIENTS], [ASSIGNMENTS], [sTATUS], [ELAPSED TIME]) VALUES( '" + cbClient.Text + "', '" + cbAssignment.Text + "', 'IDLE', '0')" The problem is the [ELASPED TIME] value added... all I need to do is initialize the cell to 0 (integer or double) But this doesn't work correctly - if I open the file (.xls) in EXCEL afterwards I get a green ! on the cell that says "Number Stored as Text" Anyone have a clue? Any help would be greatly appreciated Thanks, Quote
Administrators PlausiblyDamp Posted September 24, 2005 Administrators Posted September 24, 2005 Have you tried not putting the sigle quotes around the 0? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Shaitan00 Posted September 25, 2005 Author Posted September 25, 2005 Yup - tired that, didn't do anything Quote
mskeel Posted September 25, 2005 Posted September 25, 2005 A little trick that I learned to work with excel is to create a macro that does what you want your code to do and then observe the code that was created in the macro. In this case you want to insert a number as text, then convert it to a number. The thought I have is that maybe you can explicitly set the format of the cell to be a number and you can figure out the command for doing that via the VBA macros. Quote
herilane Posted September 25, 2005 Posted September 25, 2005 Since this isn't about automating Excel but inserting data into an existing Excel spreadsheet using ADO.NET (I presume), the macro recorder won't help you - you simply cannot record a macro that performs this action... Shaitan00, does the table already have data, or is this the first row? The reason I'm asking is that the Jet driver for Excel uses existing records to determine the data type for each column. When the table has no data, all columns are assumed to be text. This MSDN KB article has more information about this. (The article is about ADO and not ADO.NET, but the driver is the same, and none of the "ADO.NET + Excel" articles I found covers all the nitty-gritty as well as this one.) Quote
mskeel Posted September 26, 2005 Posted September 26, 2005 Since this isn't about automating Excel but inserting data into an existing Excel spreadsheet using ADO.NET (I presume)...Sorry, my confusion. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.