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
aletheia1Asked:
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.
0
 
bruintjeCommented:
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
bruintje
0
 
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?
0
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.

 
osiris247Commented:
When you say double.convert doesnt work....do you get an exception on that line??
0
 
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".
0
 
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?
0
 
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".
0
 
osiris247Commented:
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.

Steve
0
 
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 :-)
0
 
bruintjeCommented:
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
0
 
aletheia1Author Commented:
not with dataAdapter only... I tried with Command too (as your example) and I had the same problem.
0
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.