Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ADO export to Excel prepends all values with apostrophe?

Status
Not open for further replies.

Stat792

Programmer
Jan 7, 2004
12
0
0
US
I'm using c# and ADO.NET to create and write to an excel spreadsheet via the jet4.0 ole provider. Works great except that excel seems to be prepending every cell with an apostrophe! Here's some of my code:

//Create a new file
xlscnn.Open();
cmd.CommandText = "CREATE TABLE " + tablename + " (";
for (int ix = 0; ix < dt.Columns.Count; ix++)
{
cmd.CommandText += dt.Columns[ix].ColumnName + " text";
if (ix != dt.Columns.Count - 1)
cmd.CommandText += ", ";
}
cmd.CommandText += ")";
cmd.ExecuteNonQuery();


//loop through the columns and contruct the insert paratmeters
for (int ix = 0; ix < dt.Columns.Count; ix++)
{
cmd.Parameters.Add ( "@param" + ix.ToString(), System.Data.OleDb.OleDbType.VarChar, 1000);
cmd.Parameters["@param" + ix.ToString()].Value = dt.Rows[iRow][ix].ToString();
}


//Execute the insert statement
cmd.ExecuteNonQuery();
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top