@Nitin Sharma [NTSA], Welcome to Microsoft Q&A, based on my test, I reproduced your problem. According to my research, I find that Oledb only support rows inserting instead of columns inserting. Here is a code example you could refer to.
string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source="
+ path + ";Extended Properties=\"Excel 12.0 Xml; HDR=NO\";";
OleDbConnection conn = new OleDbConnection(connectionString);
string stSheetName = "Sheet1";
conn.Open();
string cmd = " insert into [" + stSheetName + "$" + "](F1,F2,F3,F4,F5,F6) values('3.1645','3.5566','4.331','3.1645','3.5566','4.331')";
OleDbCommand ole=new OleDbCommand(cmd, conn);
ole.ExecuteNonQuery();
conn.Close();
Note: we need to ensure that the first row of column has the data otherwise the code could not detect the columns F1,F2 etc..
Tested result:
Update for adding value in column:
string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source="
+ path + ";Extended Properties=\"Excel 12.0 Xml; HDR=NO\";";
OleDbConnection conn = new OleDbConnection(connectionString);
string stSheetName = "Sheet1";
conn.Open();
string[] arr = { "test1", "test2", "test3", "test4" };
OleDbCommand ole = new OleDbCommand() ;
ole.Connection=conn;
foreach (var item in arr)
{
string cmd = string.Format("insert into [{0}$](F3) values('{1}')", stSheetName, item);
ole.CommandText = cmd;
ole.ExecuteNonQuery();
}
conn.Close();
Tested result:
Hope my code could help you. Best Regards, Jack If the answer is helpful, please click "Accept Answer" and upvote it. Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.