Query & number with comma

Hi, I'm trying to insert/update some numeric field (Oracle database)

My code looks like this:
"UPDATE myTab SET myNum = TO_NUMBER('" + Request["myNum"] + ")";

I get the error --> ORA-01722: invalid number

But, if I execute the query from SQLPlus (or other DB tools), it's successful.
As far as the query is the same, why it doesn't work from .NET? Do I miss something?

I also tried Convert.ToDouble(Request["myField"]) but it doesn't work either.

Thank you
Who is Participating?
osiris247Connect With a Mentor Commented:
so doing this errors as well...??

cmd.commandtext = "UPDATE myTab SET myNum=@myNum";
cmd.parameters.addWithValue("@myNum", double.parse(Request["myNum"]);

The error number 'ORA-01722' is failed conversion from string to number. So you should not get that error doing the conversion in c#.

Break the code so you can see the value in myNum.
Hello aletheia1,

could've been a typo but there was a single quote missin in the closing part
"UPDATE myTab SET myNum = TO_NUMBER('" + Request["myNum"] + "')";

hope this helps a bit
aletheia1Author Commented:
Hi, bruintje
I just made a mistake here :-\ the original code was correct.

As I said, if I copy and paste the same query in a DB tool, it's executed succesfully.
It's weird, isn't it?

If the SQL syntax is correct, what's the problem in .NET?
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

When you say double.convert doesnt work....do you get an exception on that line??
aletheia1Author Commented:
No, I don't get any exception. The code is compiled correctly.

I get the error only when I try to execute the query... "ORA-01722: invalid number".
bruintjeConnect With a Mentor Commented:
what do you see if you step over the line?
"UPDATE myTab SET myNum = TO_NUMBER('" + Request["myNum"] + "')";

is it the same as in the db tool?
aletheia1Author Commented:
@bruintje: yes, the value is the same.
I even put a Response.Write of my query, copy and paste it in db tool. And it works there...

@osiris247: I'm using UpdateCommand of DataAdapter... is it the same?
I tried
da.UpdateCommand.Parameters.Add("@myNum", double.Parse(Request["myNum"]));
but I get the error "ORA-01036: illegal variable name/number".
Cant really comment on the updatecommand of the dataadapter...i dont use them a great deal.  Although i cant see a problem.

is the update ok if you pass a double as the param....say 10.22 ?? This would tell use whether the command is at fault or the variable being passed.

aletheia1Author Commented:
I solved the problem with this:

"UPDATE myTab SET myNum = " + Request["myNum"].Replace(",",".");

It was a problem of comma (we use comma for decimal numbers)

Anyway I splitted the points for your support. Thanks to both :-)
so the dataadapter had a problem with the comma ? because you could execute the sql in the db tool right from the code

strange but nice ot know
aletheia1Author Commented:
not with dataAdapter only... I tried with Command too (as your example) and I had the same problem.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.