PC Review


Reply
Thread Tools Rate Thread

ADO Query Question

 
 
Joe Delphi
Guest
Posts: n/a
 
      2nd Sep 2006
Hi,

I am trying to retrieve a single value from the database using ADO.
The problem is that the value in the table is $6,000,000 but the number that
always gets returned is 0. Compiles and executes with no errors, but gets
wrong answer.

Private Sub CalculateInfraCosts(ScenarioID As Integer)
Dim TotalConstCost As Double
Dim strSQL As String
Dim cmdCommand As ADODB.Command
Dim prmConstCost As ADODB.Parameter

strSQL = "SELECT TOTAL_CONST_COST " & _
"FROM tblMiscAssumptions " & _
"WHERE SCENARIO_ID = " & CStr(ScenarioID)

Set cmdCommand = New ADODB.Command
Set prmConstCost = cmdCommand.CreateParameter(adDouble, adParamOutput)
cmdCommand.Parameters.Append prmConstCost


If DBConn.State = adStateClosed Then
DBConn.Open ConnStr
End If

Set cmdCommand.ActiveConnection = DBConn
cmdCommand.CommandText = strSQL
cmdCommand.Execute

TotalConstCost =
ameters(0) -----------TotalConstCost always comes back 0 when
it should not.

MsgBox CStr(TotalConstCost)
End Sub
--------------------------------------------


Any help appreciated.

JD


 
Reply With Quote
 
 
 
 
Terry Kreft
Guest
Posts: n/a
 
      2nd Sep 2006
I don't know where you got that code from but it's complete rubbish. It
should be something like:-

Private Sub CalculateInfraCosts(ScenarioID As Integer)
Dim TotalConstCost As Double
Dim strSQL As String
Dim rs As ADODB.Recordset

strSQL = "SELECT TOTAL_CONST_COST " & _
"FROM tblMiscAssumptions " & _
"WHERE SCENARIO_ID = " & ScenarioID

If DBConn.State = adStateClosed Then
DBConn.Open ConnStr
End If

Set rs = DBConn.Execute(strSQL)

With rs
If Not(.Eof and .BOF) Then
TotalConstCost = .Fields(0)
End If
End With
MsgBox CStr(TotalConstCost)
End Sub

--

Terry Kreft


"Joe Delphi" <(E-Mail Removed)> wrote in message
news:QO6Kg.1702$8J2.673@fed1read11...
> Hi,
>
> I am trying to retrieve a single value from the database using ADO.
> The problem is that the value in the table is $6,000,000 but the number

that
> always gets returned is 0. Compiles and executes with no errors, but

gets
> wrong answer.
>
> Private Sub CalculateInfraCosts(ScenarioID As Integer)
> Dim TotalConstCost As Double
> Dim strSQL As String
> Dim cmdCommand As ADODB.Command
> Dim prmConstCost As ADODB.Parameter
>
> strSQL = "SELECT TOTAL_CONST_COST " & _
> "FROM tblMiscAssumptions " & _
> "WHERE SCENARIO_ID = " & CStr(ScenarioID)
>
> Set cmdCommand = New ADODB.Command
> Set prmConstCost = cmdCommand.CreateParameter(adDouble, adParamOutput)
> cmdCommand.Parameters.Append prmConstCost
>
>
> If DBConn.State = adStateClosed Then
> DBConn.Open ConnStr
> End If
>
> Set cmdCommand.ActiveConnection = DBConn
> cmdCommand.CommandText = strSQL
> cmdCommand.Execute
>
> TotalConstCost =
> ameters(0) -----------TotalConstCost always comes back 0

when
> it should not.
>
> MsgBox CStr(TotalConstCost)
> End Sub
> --------------------------------------------
>
>
> Any help appreciated.
>
> JD
>
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Query filter question (attempting crosstab query) joave Microsoft Access Reports 2 27th Mar 2009 08:06 PM
SELECT query vs MakeTable query - performance question macroapa Microsoft Access 2 21st Jan 2009 11:18 PM
question row filter (more of sql query question) =?Utf-8?B?YW5kcmV3MDA3?= Microsoft ASP .NET 2 6th Oct 2005 02:07 PM
query-question: mark the Row that is selected in the query DraguVaso Microsoft VB .NET 3 6th Oct 2004 01:49 PM
Query question. How do I write a query to do this? Mark Microsoft Access Queries 2 11th Aug 2004 10:03 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:36 AM.