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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP.NET C# OLE.DB.JET problem

Status
Not open for further replies.

chonthy

Programmer
Oct 4, 2007
2
HU
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:

--------------------------------------------------------------------------------------

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;\"");
connect.Open();
...
PushToXls("A", objDataset1.Tables[0].Rows[3].ToString(), objDataset1.Tables[0].Rows[4].ToString(), objDataset1.Tables[0].Rows[5].ToString(), connect);
...
connect.Close();


private void PushToXls(string table, string first, string second, string third, OleDbConnection connect)
{

OleDbParameter pmfirst, pmsecond, pmthird;


if (first != "0")
{
pmfirst = new OleDbParameter("@first", OleDbType.Numeric);
pmfirst.Value = Convert.ToInt32(first);
}
else
{
pmfirst = new OleDbParameter("@first", OleDbType.VarChar);
pmfirst.Value = "";
}
if (second != "0")
{
pmsecond = new OleDbParameter("@second", OleDbType.Numeric);
pmsecond.Value = Convert.ToInt32(second);
}
else
{
pmsecond = new OleDbParameter("@second", OleDbType.VarChar);
pmsecond.Value = "";
}
if (third != "0")
{
pmthird = new OleDbParameter("@third", OleDbType.Numeric);
pmthird.Value = Convert.ToInt32(third);
}
else
{
pmthird = new OleDbParameter("@third", OleDbType.VarChar);
pmthird.Value = "";
}

string insertCommStr = "INSERT INTO " + table + "tart VALUES (@first, @second, @third)";
OleDbCommand insertcommand = new OleDbCommand(insertCommStr, connect);
insertcommand.Parameters.Add(pmfirst);
insertcommand.Parameters.Add(pmsecond);
insertcommand.Parameters.Add(pmthird);

insertcommand.ExecuteNonQuery();

}

-----------------------------------------------------------------------------------------

I've used parametric command, but it not seems helpful.
If anybody has any idea about this problem, please share with me. :)

Thanks.
 
Maybe add a leading soace before tart:
string insertCommStr = "INSERT INTO " + table + " tart VALUES (@first, @second, @third)";


It's always darkest before dawn. So if you're going to steal your
neighbor's newspaper, that's the time to do it.
 
Hi!

Thank you so much this quick answer.
It doesn't work, because the names of the ranges are Atart, Btart, Ctart...

So, the program finds the ranges, but the INSERT command will be incorrect, I think.

Yesterday I changed the options of the JET adapter in the registry, but it didn't help me. :(
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top