Excel with OLEDB and Ado.Net - Single quote problem(')

L

Leeor Chernov

Hello,

I am trying to create a simple excel (xls) table , when creating the table I
get a ' (single quote) prefix before each value ,

how can I get rid of this single quote it is messing up my numbers with
format errors !!!



The Code I used:

public bool InsertHeader(string TitleCode, string OrderNum, string HHNum,
string StartDate, string EndDate)
{
string insertQuery = "Create Table Sheet1 ({0} String, {1}
String, {2} String, [{3}] String, [{4}] String)";

ExecuteQuery(string.Format(insertQuery, TitleCode, OrderNum,
HHNum, StartDate, EndDate));
return true;
}


public bool InsertRow(string RowCode, string ChapterStr, string
Num1, string Num2)
{
string insertQuery = "INSERT INTO [Sheet1$A:D] values
({0},'{1}',{2},{3})";
ExecuteQuery(string.Format(insertQuery, RowCode, ChapterStr,
Num1, Num2));
return true;
}

private void ExecuteQuery(string Query)
{

CurConnection = new OleDbConnection(ConStr);
string insertQuery = Query;
CurCommand = new OleDbCommand(insertQuery, CurConnection);
CurConnection.Open();
try
{
CurCommand.ExecuteNonQuery();
}
catch (Exception ex)
{

}
finally
{
CurConnection.Close();
}
}



InsertHeader("1","2","x","Y","z");
 
J

Joel

I'm not sure but you could try this

from
string insertQuery = "INSERT INTO [Sheet1$A:D] values
({0},'{1}',{2},{3})";

to
string insertQuery = "INSERT INTO [Sheet1$A:D] values
({0},{1},{2},{3})";
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top