question

ramkumar avatar image
ramkumar asked

.xls file created using bcp command cannot be opened in c#

I want a stored procedure to take backup of sq l tables and i want to retrieve and view in website.so i decided to export sql table to excel sheet(.xls) file,but when i retrieved it using Microsoft.jet.oledB driver....it throws error as EXTERNAL TABLE IS NOT IN THE SPECIFIED FORMAT...... 1.when i try to open .xls file simply,it shows the file you are trying to open,'filname.xls' is in a different format,than specified by the file extension.Verify that the file is not corrupted and is from a trusted source before opening the file...... If i create a normal .xls file manually,i could open it in c# using microsoft.jet.oledb driver..... So please give me any solution...
sql-serverbcp
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
David Wimbush avatar image
David Wimbush answered
As far as I know, you can't create an Excel file with bcp. You can give it a name that ends with .xls but that doesn't make it an Excel file. I would imagine the best way to do this is use bcp to output a CSV file. C# should be able to read that fairly easily.
2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

ramkumar avatar image ramkumar commented ·
As my requirement is to read values to display in chart,How could i read csv file into dataset in c# to display chart
0 Likes 0 ·
David Wimbush avatar image David Wimbush ramkumar commented ·
That's a programming question. You might find an answer here but I think you'd have better luck with this part of it on StackOverflow.com.
1 Like 1 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.