Re: call a function using ado



Yes, you're correct. i was in a hurry so i copied the function from the excel
vba.
I'll try your suggestion.
Thank you,
Chieko
the excel adodb connection:
Function NewFtToUtc(FT_time)
' Make a connection to the sttr sql server
' open the connection to the portal database.
' Run the stored procedure using the cell number as input.
'***************8
'Go to error line if error occurs
On Error GoTo cmdExecuteLinkedErr

' declare a few variables
Dim oConn As ADODB.Connection
Dim strConn As String
Dim strSQL As String
Dim rs As ADODB.Recordset
Dim cmdCommand As ADODB.Command
' set the query string
strSQL = "select [dbo].[FtToUtc](FT_time)"

Set oConn = New ADODB.Connection
strConn = "provider = sqloledb; Server = kuroda-port; database = pubs;
integrated security = sspi"

oConn.Open strConn
Debug.Print "The connection string is: " & oConn.ConnectionString

'Build the command text.
Set cmdCommand = New ADODB.Command
Set cmdCommand.ActiveConnection = oConn
With cmdCommand
..CommandText = "sp_ftToUtc"
..CommandType = adCmdStoredProc 'adCmdText execute stored procedure.
rs = oConn.Execute("sp_ftToUtc", , 4)
End With


'Open the recordset.
Set rs = New ADODB.Recordset
Set rs.ActiveConnection = oConn

' execute the query
rs.Open cmdCommand
'print something out.
Debug.Print rs.RecordCount
Debug.Print rs.Fields!cur_date


'set the function to equal the first record.
Set NewFtToUtc = rs.Fields!cur_date





Debug.Print NewFtToUtc & " is the new date."
rs.Close
oConn.Close
' ************
' CHECK for native jet query errors.

cmdExecuteLinkedExit:
DoCmd.Hourglass False
Exit Function

cmdExecuteLinkedErr:
'If Err.Number = dbengine.Errors(0).Number And _
'dbengine.Errors.Count > 1 Then
'For Each errAny In dbengine.Errors
' MsgBox "Error " & errAny.Number & " raised by " _
' & anyErr.Source & ": " & errAny.Description, _
' vbCritical, "cmdExecuteAttached()"
'Next errAny
'Else
MsgBox "Error " & Err.Number & " raised by " _
& Err.Source & ": " & Err.Description, _
vbCritical, "cmdExecuterAttached()"
'End If
Resume cmdExecuteLinkedExit

End Function

the fttoutc code.

returns datetime
as
begin
declare @SecondsToAdd bigint, @MilliSecToAdd bigint
declare @RetVal datetime

set @RetVal = NULL

set @SecondsToAdd = (@FtValue - 116444736000000000)/10000000
set @MilliSecToAdd = (@FtValue - 116444736000000000)/10000 -
(@SecondsToAdd * 1000)

if (@SecondsToAdd >= -2147483648) and (@SecondsToAdd <= 2147483647) and
(@MilliSecToAdd >= -2147483648) and (@MilliSecToAdd <= 2147483647)
set @RetVal = dateadd(ms, @MilliSecToAdd, dateadd(ss, @SecondsToAdd,
cast('1970-01-01 00:00:00.000' as datetime)))

return @RetVal
end

"Erland Sommarskog" wrote:

> chieko (chieko@xxxxxxxxxxxxxxxxxxxxxxxxx) writes:
> > Thanks for reading my question.
> > the function converts integer utc time to eastern standard time.
> > Function FtToUtc(FT_time)
> >
> > '(@FtValue bigint)
> > 'returns DateTime
> >
> > Dim SecondsToAdd As Double
> > Dim MilliSecToAdd As Double
> > Dim GMT As Date
> > Dim newDate As Date
> > Dim num As Double
> > GMT = #1/1/1970#
> >
> > 'declare @RetVal datetime
> >
> > 'set @RetVal = NULL
> > If (FT_time <> 0) Then
> > SecondsToAdd = (FT_time - 1.16444736E+17) / 10000000
> > MilliSecToAdd = ((FT_time - 1.16444736E+17) / 10000 - (SecondsToAdd *
> > 1000)) / 1000
> >
> > If (SecondsToAdd >= -2147483648#) And (SecondsToAdd <= 2147483647) And _
> > (MilliSecToAdd >= -2147483648#) And (MilliSecToAdd <= 2147483647) Then
> > newDate = DateAdd("s", SecondsToAdd, GMT)
> > FtToUtc = DateAdd("s", MilliSecToAdd, DateAdd("s", SecondsToAdd, GMT))
> > End If
> > Else: FtToUtc = 0
> > End If
> > End Function
> >
> > and in visual basic i am using adodb to connect to the sql server then
> > tried to issue the command:
> > recordset_rst = fttoutc(cell number)
> > I can provide the vb code when i have it available...later today maybe.
>
> Judging from your previous post, this function of yours lives in SQL
> Server, although the syntax indicates different.
>
> But if the function indeed lives in SQL Server, and you issue
>
> recordset_rst = fttoutc(cell number)
>
> from Excel, then Excel is not going to look for the function in SQL
> Server.
>
> Rather you would need to do something like:
>
> cmd.CommandType = adStoredProcedure
> cmd.CommandText = "dbo.FtToUtc"
> cmd.CreateParameter "@retval", adDBTimeStamp, adParamReturnValue
> cmd.CreateParameter "@input", adDBTimeStamp, adParamInputValue, , _
> cellvalue
> cmd.Execute ,adReturnNoRecords
> returnvalue = cmd.Parmeters("@retval")
>
> --
> Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx
>
> Books Online for SQL Server 2005 at
> http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
> Books Online for SQL Server 2000 at
> http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
>
.



Relevant Pages

  • runtime error in my application
    ... when iam running a process called convertin my application ... which is to convert data from excel sheet to sql server table it's giving me ... This process is to convert data From EXcel file to ... Dim oSheet As Excel.Worksheet ...
    (microsoft.public.vb.bugs)
  • Re: Text file import is dropping records
    ... Excel and Access behaves a little differently than of SQL Server. ... Server is doing is combine your data until the fixed number of character are ... Dim objFileSystem ...
    (microsoft.public.sqlserver.dts)
  • Re: Export Data To A Specific Cell in Excel
    ... Named Ranges appear to SQL Server as a table. ... You are going to have to use an Active X Script task, ADO, The Excel Object Model and a bit of ingenuity. ... Dim e_wksheet ...
    (microsoft.public.sqlserver.dts)
  • runtime error in the application
    ... when iam running a process called convertin my application ... which is to convert data from excel sheet to sql server table it's giving me ... This process is to convert data From EXcel file to ... Dim oSheet As Excel.Worksheet ...
    (microsoft.public.vb.bugs)
  • runtime error in application
    ... when iam running a process called convertin my application ... which is to convert data from excel sheet to sql server table it's giving me ... This process is to convert data From EXcel file to ... Dim oSheet As Excel.Worksheet ...
    (microsoft.public.vb.bugs)

Loading