Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
In the excel sheet, I have more than 1 lac rows. Am trying to update specific cell and row. It's working and does the update only up to certain row but when I try A106880 row it's saying ' Make sure the object exists and that you spell its name and the path name correctly.'

C#
string sConnection = string.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=""Excel 12.0 Xml;HDR=No;IMEX=1""", path);
OleDbConnection _Connection = new OleDbConnection(sConnection);
_Connection.Open();
string cmd = string.Format("Update [{0}$A106880:A106880] set F1 = 12", sheetname);
System.Data.OleDb.OleDbCommand myCommand = new System.Data.OleDb.OleDbCommand(cmd, connection);
if (myCommand != null) myCommand.ExecuteNonQuery();
_Connection.Close();


Thanks in advance,
Posted
Updated 7-Feb-16 17:16pm
v2
Comments
[no name] 8-Feb-16 0:34am    
At which line it is throwing error, please provide details.
kvchennai 8-Feb-16 2:06am    
here
myCommand.ExecuteNonQuery();


or if I have update query to update specific cell without using header column. Let say by using row no. like A106880...
kvchennai 8-Feb-16 2:07am    
like this "Update [sheetname$] set F5 = 12 where rowno. = 12400"

1 solution

You have two different spellings for your connection object, which one is correct?
C#
OleDbConnection _Connection = new OleDbConnection(sConnection);
_Connection.Open();   // ***** _Connection
string cmd = string.Format("Update [{0}$A106880:A106880] set F1 = 12", sheetname);

System.Data.OleDb.OleDbCommand myCommand = new System.Data.OleDb.OleDbCommand(cmd, connection);   // ***** connection
 
Share this answer
 
Comments
kvchennai 8-Feb-16 5:49am    
Actually I have copied that code from two functions, that's why spelling mistake.

Just now I got to know that problem with excel limitation. Old version (xls) supports max. 65536 rows and new format (xlsx) support 1048576 rows. Now issue is, even with the new version I couldn't able to pass more than 65536 like [{0}$A65537:A65537] due to limitation but it can be possible when I use 'where' condition. But 'where' takes more time to update doc. Please help me or how to use row no. in 'where' condition instead of column name and value
Richard MacCutchan 8-Feb-16 9:09am    
If you have problems with one function then why show code from another? If you expect people to help you, then please ensure you post accurate details of the problem, so we don't waste time with such answers.

As to the addressing problem, I have never tried this so cannot comment further. I would suggest studying the Excel documentation.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900