0
static string connStrCheckData = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Server.MapPath("test.xlsx") + ";Extended Properties=Excel 12.0;";
 
static string      oledbConnCheckData = new OleDbConnection(connStrCheckData);

string adsName ="MagMall.com - subscription savings on 1,000's of magazines";

OleDbCommand cmd = new OleDbCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "insert into  [sheet1$] ( [column1]) values ('" + adsName.ToString().Trim() + "')";
cmd.Connection = oledbConnCheckData;

oledbConnCheckData.Open();

cmd.ExecuteNonQuery();

oledbConnCheckData.Close();

Errro : Syntax error (missing operator) in query expression ''MagMall.com - subscription savings on 1,000's of magazines')'.

Above Error occurs when I tried to insert: "MagMall.com - subscription savings on 1,000's of magazines" word.

eglease
  • 2,445
  • 11
  • 18
  • 28
Shailesh
  • 13
  • 7

2 Answers2

1

As juergen said, you hve to escape the single apostrophe buy adding an additional one: 1,000''s (not \'). The double apostrophies is the correct way to pass the statement.

Eddie Paz
  • 2,219
  • 16
  • 11
0

You have to escape the ' in 1,000's like this 1,000\'s

juergen d
  • 201,996
  • 37
  • 293
  • 362