oledb - The INSERT INTO statement contains the following unknown field name: 'a'. Make sure you have typed the name correctly, and try the operation again -


// e,g, want insert 3 columns in 1st row , 10 columns in rest of rows //i creating excel file sheet name mysheet // updating value in 1st row, 1st cell of header blank //then inserting data // can please insert data in excel without header

string connectionstring = "provider=microsoft.ace.oledb.12.0;data source=" + filename +     ";mode=readwrite;extended properties=\"excel 12.0 xml;hdr=no\"";      using (oledbconnection conn = new oledbconnection(connectionstring))     {     conn.open();      using (oledbcommand cmd = new oledbcommand())     {         cmd.connection = conn;         cmd.commandtext = "create table [mysheet] (a string)";         cmd.executenonquery();          cmd.commandtext = "update [mysheet$] set f1 = \"\"";         cmd.executenonquery();          cmd.commandtext = "insert  [mysheet] (a) values ('abc')" //<-----getting error insert         cmd.executenonquery();     } }     conn.close(); 

just try [removed (a)]

cmd.commandtext = "insert  [mysheet] values ('abc')";  

Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -