A problem when use create excel file using Microsoft excel ODBC dr

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,

I'm using Microsoft excel ODBC driver to create .xls file. The code looks
like this,

Foo()
{
CDatabase db;
CString openStr;


openStr.Format("DRIVER={%s};DSN='';FIRSTROWHASNAMES=1;READONLY=FALSE;CREATE_DB=\"%s\";DBQ=%s","MICROSOFT
EXCEL DRIVER (*.XLS)", "c:\\test.xls", "c:\\test.xls");

if (db.OpenEx(openStr,CDatabase::noOdbcDialog))
{
// Create table
openStr.Format ("CREATE TABLE %s (%s TEXT,%s TEXT,%s TEXT,%s TEXT)",
"testTable",
"Item1",
"Item2",
"Item3",
"Item4"
);
db.ExecuteSQL (openStr);

// Fill content
openStr.Format ("INSERT INTO testTable (Item1,Item2,Item3,Item4) VALUES
('%s','%s','%s',%s')",
"Value1",
"Value2",
"Value3",
"Value4",
"Value5"
);
db.ExecuteSQL (openStr);
}
return ;
}

After this function running, the "c:\test.xls" is created successfully and
everything looks OK except the values inputted ("ValueX") were all prefixed
by a '. It may because the "ValueX" was by a pair of ' in the SQL command.
But if I remove the ', the SQL then has syntax error.

Anyone knows how to remove the extra '? Thanks in advance.
 
This behaviour is by design. It ensures Excel (and Jet) sees the value
as text. It should not cause you any problems so just try to forget
about it <g>.

Jamie.

--
 
It's a bad news.:-)

Really? I'm genuinely interested: what problems is it causing you?
Thanks,
Jamie.

--
 
As I thought. Silence speaks volumes. People think the ' will be a
problem but it never is.

Jamie.

--
 

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

Back
Top