I need to read an Excel work book with 2 sheet which have more than 60,000 records. The application is an ASP.Net application so the performance matters.
Which approach should I take? Sohuld I do it using Microsoft.Office.Interop.Excel or should I do it using OLEDB in ADO.Net?
I got an error about OleDB. I just want my excel file import to Gridview. Here is my code.
string connstr = "Provider=Microsoft.Jet.Oledb.4.0;Data Source=C:a.xls;Extended Properties=Excel 8.0;HDR=YES;IMEX=1"; OleDbConnection conn = new OleDbConnection(connstr); string strSQL = "Select * from [Sheet1$]"; OleDbCommand cmd = new OleDbCommand(strSQL, conn); DataSet ds = new DataSet(); OleDbDataAdapter da = new OleDbDataAdapter(cmd); da.Fill(ds); GridView1.DataSource = ds; GridView1.DataBind();
When i build project there is no error but when i run this project i got an error like this:
System.ArgumentException:Format of the initialization string does not conform to specification starting at index 47. Line 21: string connstr = "Provider=Microsoft.Jet.Oledb.4.0;Data Source=C:a.xls;Extended Properties=Excel 8.0;HDR=YES;IMEX=1"; Line 22: Line 23: OleDbConnection conn = new OleDbConnection(connstr);
i got the following error while i am trying to get my web application to run on windows server 2003. I've installed 2007 data access components on windows server 2003 but the web application does not seem to work. The codes that i use is as follows:
[code]....
I've read a lot of forum posts and almost all of them mentioned ab out the connectionstring being wrong. However, when i ran the codes on my local machine, there were no errors. The error only show when i was running on windows server 2003.
When I am trying to export data from gridview to excel i an also getting hyperlink along with that, how can i remove that before export. below is my code
<div align="right" style="padding-top:5px; padding-right:5px"> <span title="Export Data to Excel"><asp:ImageButton ID="btnExporttoExcel" runat="server" ImageUrl="~/img/Excel_Logo.png" onclick="btnExporttoExcel_Click" /></span> <span title="Export Data to Word"><asp:ImageButton ID="btnExporttoWord"
Is there a way to import an amount of data from an excel sheet using the sheet rowindex, something like: SELECT * FROM [PLAN1$] WHERE ROWINDEX BETWEEN 1 AND 1000?
I am using asp.net oledb to export information to excel file. I encounter problems when the information to export becomes too big, in this case the code I have given below, the excel file generated becomes an empty spreadsheet. If I changed the loop to 1123 for insertion of the rows. The generated excel file is fine, 1125 rows, and 4 columns shown. A test program in windows form is also working fine regardless of how many rows. Code has been simplified, "information ..." in the sql insertion command represents 1803 characters.
ExcelObjConn = "Provider=Microsoft.Ace.OLEDB.12.0;" & _ "Data Source=" & fileName & ";Extended Properties=Excel 12.0 XML" ExcelConnection = New System.Data.OleDb.OleDbConnection(ExcelObjConn) ExcelConnection.Open() Try SqlCommand = "CREATE TABLE ABC ([row1] text, [row2] text, [row3] text, [row4] text)" ExcelCommand = New OleDb.OleDbCommand(SqlCommand, ExcelConnection) ExcelCommand.ExecuteNonQuery() ExcelCommand.Dispose() For i As Integer = 0 To 1124 SqlCommand = "Insert into ABC ([row1], [row2], [row3], [row4]) Values ('information...', 'information ...', 'information ...', 'information ...')" ExcelCommand = New OleDb.OleDbCommand(SqlCommand, ExcelConnection) ExcelCommand.ExecuteNonQuery() ExcelCommand.Dispose() Next Catch ex As Exception Finally If ExcelConnection IsNot Nothing Then ExcelConnection.Close() ExcelConnection.Dispose() End If End Try
I couldn't find a solution to my problem as well. What I did eventually was to run the process using another separate windows service. The code works perfectly fine running from a windows form or service program, but not asp.net, not sure why.
Public Function UploadExcelFile2003(ByVal excelSheet As String, ByVal filePath As String, ByVal header As String, ByVal dataTable As String) As Integer Dim intRetValue As Integer Try dataTable = "Student" strConnection = ConfigurationManager.ConnectionStrings("TDPdb").ToString conn = New SqlConnection(strConnection) cmd = New SqlCommand("stp_ImportFromExcel03", conn) cmd.CommandType = CommandType.StoredProcedure cmd.Parameters.Add("@SheetName", SqlDbType.VarChar).Value = excelSheet cmd.Parameters.Add("@FilePath", SqlDbType.VarChar).Value = filePath cmd.Parameters.Add("@HDR", SqlDbType.VarChar).Value = "Yes" cmd.Parameters.Add("@TableName", SqlDbType.VarChar).Value = dataTable cmd.Parameters.Add(New SqlParameter("@ReturnValue", SqlDbType.Int)).Direction = ParameterDirection.ReturnValue conn.Open() cmd.ExecuteNonQuery() - ERROR conn.Close() intRetValue = CType(cmd.Parameters("@ReturnValue").Value, Integer) Catch ex As Exception Session("LastErrorMsg") = ex.Message 'catch any last error message End Try Error msg:
The OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "(null)" does not contain the table "Sheet1$". The table either does not exist or the current user does not have permissions on that table. Is it because I do not have sufficient rights for my SQL? How do I configure them?
I want to fetch data from a excel sheet. Can anyone tell me how we can acheive this I also want to edit that data and then again place it on excel sheet.
If I use Microsoft.Jet.OLEDB.4.0 to retreive for example named range or sheet from Excel and use it as data source for some server control on the ASP page, everything works fine. But when I try to get table from Excel like this: "select * from [Table1]", debugger complains that database engine could not find object Table1. So how should I reference Table1 in Excel file so that the database engine could find it?
string strFileName = FileUpload1.PostedFile.FileName; string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + strFileName + ";" + "Extended Properties=Excel 8.0;"; OleDbConnection objConn = new OleDbConnection(connectionString); objConn.Open(); String strConString = "SELECT * FROM [Product Classification 5$]"; //where date = CDate('" + DateTime.Today.ToShortDateString() + "')"; OleDbCommand objCmdSelect = new OleDbCommand(strConString, objConn); // Create new OleDbDataAdapter that is used to build a DataSet // based on the preceding SQL SELECT statement. OleDbDataAdapter objAdapter1 = new OleDbDataAdapter(); // Pass the Select command to the adapter. objAdapter1.SelectCommand = objCmdSelect; // Create new DataSet to hold information from the worksheet. DataSet objDataset1 = new DataSet(); objAdapter1.Fill(objDataset1, "ExcelData");
but in it doesnt read the Description data of 20 & 30 because somebody said if the first cell value is string type then all the column should be string but in mycase its coming as mixed(alpha & numeric), so that it cant read the data, i tried to convert the column as Text then also the same problem continues,
Im reading some data from the excel file, using below code
objBusy = new BusinessLogic(); string strFileName = FileUpload1.PostedFile.FileName; string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + strFileName + ";" + "Extended Properties=Excel 8.0;"; OleDbConnection objConn = new OleDbConnection(connectionString); objConn.Open(); String strConString = "SELECT * FROM [Product1$]"; //where date = CDate('" + DateTime.Today.ToShortDateString() + "')"; OleDbCommand objCmdSelect = new OleDbCommand(strConString, objConn); // Create new OleDbDataAdapter that is used to build a DataSet // based on the preceding SQL SELECT statement. OleDbDataAdapter objAdapter1 = new OleDbDataAdapter(); // Pass the Select command to the adapter. objAdapter1.SelectCommand = objCmdSelect; // Create new DataSet to hold information from the worksheet. DataSet objDataset1 = new DataSet(); objAdapter1.Fill(objDataset1, "ExcelData");
after this if i looks on the DataSet i see some of the cell value not read from the Excel file, what was the problem and how to resolve this?