Reputation: 3312
I want to update the specific cell of the excel file using oledb. Say I7 cell, for some reason always I1 is getting updated. Can anyone tell me what's wrong with this code?
OleDbConnection oledbConn = new OleDbConnection(connString);
oledbConn.Open();
// I want to set the value of I7 cell to 22, for some reason value is I1 is getting updated :(
OleDbCommand cmd = new OleDbCommand("UPDATE [" + sheetName + "$I7:I7] SET F1=22", oledbConn);
int result = cmd.ExecuteNonQuery();
Console.WriteLine(result);
oledbConn.Close();
Upvotes: 0
Views: 7169
Reputation: 19
i read this blog how Atul Sureka said forums.asp.net/t/1214491.aspx/1 " This link may help you:
http://www.pcreview.co.uk/forums/thread-1176677.php
To update a single cell in an existing table you use HDR=No in the extended properties of the connection string and use UPDATE sql syntax such as:
UPDATE [Sheet3$A2:A2] SET F1='TestValue1';
F1 is the default name Jet assigns to the first column where the column name is unknown or invalid. The inserted value must match the data type for the whole column. "
Upvotes: 0
Reputation: 3312
I ran the same program on excel 2007, it worked smoothly. For excel 2013 it does not work. Seems like a bug in excel 2013.
Upvotes: 0
Reputation: 35470
This may purely be an issue with the cell address scheme you're using. Try $I$7:$I$7
intsead. Also, what is that F1
thing in the query?
Upvotes: 1