ajay raju

ajay raju

  • NA
  • 398
  • 0

import excel data to datagrid?

Aug 27 2010 1:06 AM


Hi
 
A File upload area where the person can select an excel file to upload, a button to upload and then a datagrid which will display the uploaded data.
 
how to do this?

The details in this gridview are then saved to a database but before that they can be edited and some rows removed if necessary
i tried to display Excel to Datagrid but Error is occured when i Fill the data into dataset that Error message is Cannot update.  Database or object is read-only. my code is:

Dim savePath As String = "~/ExcelFiles/"
Dim fileName As String = Server.HtmlEncode(fuImportContacts.FileName)
savePath = savePath & fileName

Dim strCon As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=Server.MapPath(savePath);" & "Extended Properties=Excel 8.0;"

Dim ds As DataSet = New DataSet()
Dim da As OleDbDataAdapter = New OleDbDataAdapter("SELECT * FROM [SHEET1$]", strCon)
da.TableMappings.Add("Table", "ExcelTest")
da.Fill(ds)

DataGrid1.DataSource = ds.Tables(0)
DataGrid1.DataBind()

please give a solution
Thanks

Answers (1)