473,387 Members | 2,436 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Problem in import and export to excel

Hi,

I have a problem in importing from an excel file. I am using the connection string for oledb to convert the data from the excel file into a datatable and proceed thereafter. Code I am using is as given below:

excelConn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & fileName & ";Extended Properties=""Excel 8.0;HDR=Yes;""")

excelConn.Open()

Dim dbSchema As DataTable = excelConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tabl es, Nothing)

If dbSchema Is Nothing OrElse dbSchema.Rows.Count < 1 Then

Throw New Exception("Error: Could not determine the name of the first worksheet.")

End If

Dim firstSheetName As String = dbSchema.Rows(0)("TABLE_NAME").ToString

Dim dbCommand As OleDbCommand = New OleDbCommand("SELECT * FROM [" + firstSheetName + "]", excelConn)

'excelConn.Open()

oledbDA = New OleDbDataAdapter("SELECT * FROM [" + firstSheetName + "]", excelConn)

oledbDA.Fill(fcstImportDS)



It is able to read some of the excel files correctly. But in the cases when i am renedring a datagrid to excel file then it is unable to read those excel files and giving exception having no name. The i am using for downloading datagrid to excel is as given below:

dgExportToExcel.DataSource = userAllGenericStrategiesDT

dgExportToExcel.DataBind()

Response.Clear()

Response.AddHeader("Content-Disposition", "attachment;filename=" & fileName)

Response.Charset = ""

Response.ContentType = "application/vnd.ms-excel"

Dim controlOutputBuffer As System.IO.StringWriter

Dim controlOutput As HtmlTextWriter

controlOutputBuffer = New System.IO.StringWriter()

controlOutput = New HtmlTextWriter(controlOutputBuffer)

''Render the datagrid control.

dgExportToExcel.RenderControl(controlOutput)

''Write the contents of the control output to the response stream

Response.Write(controlOutputBuffer.ToString())

Response.Flush()

Response.End()



Can any body help me on this, why it is not able to read from the downloaded excel files?(If i open the same downloaded file and again save it as an excel file, it is able to read correctly. One thing i can see is when i open the downloaded excel file and click "Save AS" button, it shows me option for type as Web Page)



Thanks,

Santosh.
Sep 7 '06 #1
0 2840

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Damien | last post by:
Hi to all, I need to design an import/export system. Data comes from a filemaker pro DB in a big CSV file. Some alterations are made on the data as it is imported into my mysql table. Data is...
2
by: Hon Seng Phuah | last post by:
Hi all, I have a huge excel format file wants to export to sql server database. One of the field has combination of numeric and alphanumeric. When I import the excel format to sql server...
8
by: mytfein | last post by:
Hi Everyone, Background: Another department intends to ftp a .txt file from the mainframe, for me to process. The objective is to write a vb script that would be scheduled to run daily to...
1
by: congngo | last post by:
Hi all Every time I export a table into an excel spreadsheet. It has a leading apostrophe on every cells. This drive me nut. I have to do a work around by export table into a txt file than...
1
by: Jonathan Woods | last post by:
Hi there, how do u handle export/import data between your App and other data sources(e.g. excel spreedsheet). use DTS package? How do u do that?
10
by: Niklas | last post by:
Hi Before I start coding I need to be sure that nobody else has not done it yet and that I can use it. I need an import utility which import data from Excel to a database or some object in...
1
by: Pauline | last post by:
Dear all, I have an enormous database (Access 2003) containing sales information, and an Excel tool to enable end users to do planning and forecasting. Untill now I would create several queries,...
4
by: Max2006 | last post by:
Hi, We are developing a SQL server based asp.net application. As part of requirement we should allow users import/export some relational data through web user interface. We are investigation...
5
by: sumanta123 | last post by:
Dear Sir, How to export/import the excel file in oracle database using sql promt. Please guide me the command(export/import) for the neddful. Thanks in Adavance. Regards Sumanta Panda
2
by: thesti | last post by:
hello, how to programmatically from VB .net / php. to import data from an EXCEL file? is there's no programmatic way, how to automated the process. as i search, the process is: Simply...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.