6
I’m having a hard time solving this mistake.
My goal is to collect data from an Excel file and store it in c#variables, which in turn will be inserted into SQL Server 2012.
Reading is done line by line.
Here’s the code where the error happens:
Excel.Application excelApp = new Excel.Application();
Excel.Workbook WB = null;
Excel.Worksheet WS = null;
excelApp.Visible = false;
Convert.ToString(FileUpload1.PostedFile.FileName);
Response.Write(FileUpload1.PostedFile.FileName);
string excelpath = FileUpload1.PostedFile.FileName;
Convert.ToString(excelpath);
string workbookPath = excelpath;
WB = excelApp.Workbooks.Open(workbookPath, 0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);
WS = excelApp.Worksheets.get_Item("" + TextBox2.Text);
String connectionString =
"Data Source=localhost;" +
"Initial Catalog=Teste;" +
"User id=sa;" +
"Password=123;";
Excel.Range last = WS.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell);
Excel.Range range = WS.get_Range("A1", last);
object ranger = range.Value;
Error:
An Exception of type 'System.Outofmemoryexception' occurred in mscorlib.dll but was not handled in user code Asp.net
Do you really have to store everything in variables? https://msdn.microsoft.com/pt-br/library/system.outofmemoryexception(v=vs.110). aspx
– TotallyUncool
yes to then make a query to enter them correctly in the database. but the problem is not there
– Diogo Gomes
please I really need help
– Diogo Gomes
How many lines are being read?
– TotallyUncool
Close to 400 rows and 142 columns. I know it is possible using these methods but something is going wrong .
– Diogo Gomes
Creates a table similar to the spreadsheet in the DB, then inserts row by row not to load everything at once in the variable, applies its business rule in this table, transports the data to the respective tables and clears the manipulation table at the end of the process. Or request a memory UP on the server.
– Daniel Gregatto