?
Solved

Query & number with comma

Posted on 2006-05-11
11
Medium Priority
?
366 Views
Last Modified: 2012-05-05
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
0
Comment
Question by:aletheia1
  • 5
  • 3
  • 3
11 Comments
 
LVL 44

Expert Comment

by:bruintje
ID: 16656155
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
 

Author Comment

by:aletheia1
ID: 16656223
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
 
LVL 7

Expert Comment

by:osiris247
ID: 16656511
When you say double.convert doesnt work....do you get an exception on that line??
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:aletheia1
ID: 16656655
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
 
LVL 44

Assisted Solution

by:bruintje
bruintje earned 100 total points
ID: 16656673
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
 
LVL 7

Accepted Solution

by:
osiris247 earned 100 total points
ID: 16656686
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
 

Author Comment

by:aletheia1
ID: 16656723
@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
 
LVL 7

Expert Comment

by:osiris247
ID: 16657132
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
 

Author Comment

by:aletheia1
ID: 16657666
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
 
LVL 44

Expert Comment

by:bruintje
ID: 16657724
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
 

Author Comment

by:aletheia1
ID: 16658223
not with dataAdapter only... I tried with Command too (as your example) and I had the same problem.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses
Course of the Month13 days, 10 hours left to enroll

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question