![]() |
|
|
Welcome to the { mindfrost82.com } forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
Excel with Ado.Net and OLEDB problem -
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"); |
|
|||
|
Re: Excel with Ado.Net and OLEDB problem -
Ummmmmmm ... maybe it's to do with the fact that the values you are writing
to the sheet are, in fact, strings. If you want numbers then write numbers. "Leeor Chernov" <leeor_chernov@mod.gov.il> wrote in message news:eHgkYu21IHA.5472@TK2MSFTNGP06.phx.gbl... > 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"); > > > |
|
|||
|
Re: Excel with Ado.Net and OLEDB problem -
Ummmmmmm ... maybe it's to do with the fact that the values you are writing
to the sheet are, in fact, strings. If you want numbers then write numbers. "Leeor Chernov" <leeor_chernov@mod.gov.il> wrote in message news:eHgkYu21IHA.5472@TK2MSFTNGP06.phx.gbl... > 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"); > > > |
![]() |
|
| Thread Tools | Search this Thread |
| Display Modes | |
|
|