By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,846 Members | 2,094 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,846 IT Pros & Developers. It's quick & easy.

ASP.NET C# and OLEDB.JET problem

P: 1
Hello!

I'm in trouble with the ASP.NET and OLEDB.JET connector.
When I put the data into an XLS file from a dataset of my webpage, everything's OK, but in the destination file there is an apostrophe in front of every numeric data.
It's problem for me, because there are some aritmethical operation with my datas in the XLS.
Here is my source code, what put the data into the file:

Expand|Select|Wrap|Line Numbers
  1. OleDbConnection connect = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath(docpath)+"myfile.xls;Extended Properties=\"Excel 8.0;Readonly=False;IMEX=0;\"");
  2. connect.Open();
  3. ...
  4. PushToXls("A", objDataset1.Tables[0].Rows[i][3].ToString(), objDataset1.Tables[0].Rows[i][4].ToString(), objDataset1.Tables[0].Rows[i][5].ToString(), connect);
  5. ...
  6. connect.Close();
  7.  
  8.  
  9. private void PushToXls(string table, string first, string second, string third, OleDbConnection connect)
  10.     {
  11.  
  12.             OleDbParameter pmfirst, pmsecond, pmthird;
  13.  
  14.  
  15.             if (first != "0")
  16.             {
  17.                 pmfirst = new OleDbParameter("@first", OleDbType.Numeric);
  18.                 pmfirst.Value = Convert.ToInt32(first);
  19.             }
  20.             else
  21.             {
  22.                 pmfirst = new OleDbParameter("@first", OleDbType.VarChar);
  23.                 pmfirst.Value = "";
  24.             }
  25.             if (second != "0")
  26.             {
  27.                 pmsecond = new OleDbParameter("@second", OleDbType.Numeric);
  28.                 pmsecond.Value = Convert.ToInt32(second);
  29.             }
  30.             else
  31.             {
  32.                 pmsecond = new OleDbParameter("@second", OleDbType.VarChar);
  33.                 pmsecond.Value = "";
  34.             }
  35.             if (third != "0")
  36.             {
  37.                 pmthird = new OleDbParameter("@third", OleDbType.Numeric);
  38.                 pmthird.Value = Convert.ToInt32(third);
  39.             }
  40.             else
  41.             {
  42.                 pmthird = new OleDbParameter("@third", OleDbType.VarChar);
  43.                 pmthird.Value = "";
  44.             }
  45.  
  46.             string insertCommStr = "INSERT INTO " + table + "tart VALUES (@first, @second, @third)";
  47.             OleDbCommand insertcommand = new OleDbCommand(insertCommStr, connect);
  48.             insertcommand.Parameters.Add(pmfirst);
  49.             insertcommand.Parameters.Add(pmsecond);
  50.             insertcommand.Parameters.Add(pmthird);
  51.  
  52.             insertcommand.ExecuteNonQuery();
  53.  
  54.     }
I've used parametric command, but it not seems helpful.
If anybody has any idea about this problem, please share with me. :)

Thanks.
Oct 4 '07 #1
Share this Question
Share on Google+
1 Reply


jhardman
Expert 2.5K+
P: 3,405
HI and welcome to the scripts Developer Network. I have moved your post to the .NET forum (there is a technical difference between ASP and ASP.NET. The latter is a part of the .NET package and belongs here). I have also added code tags to your post to make it more readable. Please do this yourself in the future (notice the button marked - # -)

Jared, moderator
ASP forum
Oct 5 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.