473,320 Members | 1,926 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

ExecScalar() in OracleClient

The .ExecScalar method of the OracleClient seems to have a
bug. If I call it with a query that returns a number it
executes fine. However, it I attempt to return a string
if returns "0" and generates an unusual error message:
invalid cast from string to integer (see code below).

Is this a bug or is there a trick to making this work?

Anyone?
The following function works fine with "Select Count(*)
From table"; fails with "Select TextField From Table"

Function ExecScaler(psSQL as String, psConnect as String)
as Object
Dim oCmd As New OracleCommand()
Dim oConn As New OracleConnection()
oConn.ConnectionString = psConnect
With oCmd
.Connection = oConn
oConn.Open()
.CommandText = psSQL
ExecScalar = .ExecuteScalar()
End With
End Function
Jul 21 '05 #1
1 2193
Hi AlexB,

I tried, but I cannot reproduce the problem on my side.

I am using the following table:

CREATE TABLE "SYSTEM"."TEST"("NAME" VARCHAR2(50) NOT NULL)

In the talbe, I have the following rows:

NAME
--------------------------------------------------
1
2
3
4
5
0

6 rows selected.

The following is my code:

Function ExecScalar(ByVal psSQL As String, ByVal psConnect As String)
As Object
Dim oCmd As New OracleCommand()
Dim oConn As New OracleConnection()
oConn.ConnectionString = psConnect
With oCmd
.Connection = oConn
oConn.Open()
.CommandText = psSQL
ExecScalar = .ExecuteScalar()
End With
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
MsgBox(ExecScalar("select count(*) from test",
"Server=chinaora.orcl;Uid=system;Pwd=manager") )
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
MsgBox(ExecScalar("select name from test where name='0'",
"Server=chinaora.orcl;Uid=system;Pwd=manager") )
End Sub

Everything works as expected.

Please try the above your sides. Any Qs, please reply to this post.

--
Parker Zhang
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.

Jul 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Kevin Vogt | last post by:
When initially loaded, my web application (below) takes ~120000 milliseconds to open its connection. But repeated executions take 0 milliseconds each. But when I wait for approx. 5 minutes and try...
2
by: JJ | last post by:
Hi, I don't know if this is the correct newsgroup to post this question, but here goes. I have installed Visual Studio .Net Professional 2003. I checked the version and it is 7.1.3088. It...
0
by: George | last post by:
I have an aspx page, this page instance a Dll make for me, this Dll imports System.Data.OracleClient, I Add the Reference in the project and use the gcautil -i but the error "Namespace or type...
1
by: AlexB | last post by:
The .ExecScalar method of the OracleClient seems to have a bug. If I call it with a query that returns a number it executes fine. However, it I attempt to return a string if returns "0" and...
3
by: Richard Lewis Haggard | last post by:
Is the OracleClient class still alive and well? I see that the online documentation has a warning in big red letters, "Note: This namespace, class, or member is supported only in version 1.1 of the...
3
by: =?Utf-8?B?RFNJU3VwcG9ydA==?= | last post by:
I have an ASP.NET application runinng on IIS 5 .NET 1.1 Sp1 and recently we've been experiencing this error when the users are trying to print reports that connects to Oracle database. The only way...
4
by: =?Utf-8?B?RFNJU3VwcG9ydA==?= | last post by:
Hi, I have this ASP.NET application developed with VS.NET 2003 VB.NET and deplyed on Windows 2K server IIS 5. This application uses the following: - Oracle 10G databse - MS Data Access Block...
4
by: vbcsdotnet | last post by:
hello I run an sql which returns a datarow itemarray field of system.datetime. the problem is the database only stores the date, but the returned value includes a time of 12:00:00 AM. I do not...
0
by: =?Utf-8?B?Q2hhbmUgRw==?= | last post by:
We recently updated our web service from .Net 1.1 to .Net 2.0. Our web services are using the Oracle Client provided by Microsoft. We are now randomly getting the following error when accessing...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.