none
problem with Stored procedure returning getdate() RRS feed

  • Question

  • I dont Know if my problem is caused by the stored procedure or by visual studio. I have a simple stored procedure i wrote in sql server 2005 called getSQLtime:

     

    ALTER PROCEDURE [dbo].[GetSQLtime]

    -- Add the parameters for the stored procedure here

    @outpar datetime output

    AS

    BEGIN

    -- SET NOCOUNT ON added to prevent extra result sets from

    -- interfering with SELECT statements.

    SET NOCOUNT ON;

    -- Insert statements for procedure here

    SET @outpar= getdate()

    END

     

     

    Using the wizard, I imported this procedure in my dataset to retrieve the time from the server. But I cant seem to figure out how to set the value of a variable in Visual basic 2008 to the output parameter (the getdate()). Intellisense says this about my GetSQLtime function:

     

    Public Overloads Overridable Function GetSQLtime(ByRef outpar As Date?) As Integer

     

    If I try to use the function:

    Dim QTA As New localOMSDataSetTableAdapters.QueriesTableAdapter

    Dim theTime As DateTime = Today

    QTA.GetSQLtime(theTime)

     

     I always get an error:

     

    Error 1 Option Strict On disallows narrowing from type 'Date?' to type 'Date' in copying the value of 'ByRef' parameter 'outpar' back to the matching argument.

     

    Thx for any help or any other simple method to retrieve the getdate() from my server.

    Sunday, July 20, 2008 10:44 PM

Answers

  • Apparently there is a narrowing conversion somewhere during the return of the call to the stored procedure, or the stored procedure parameter in the TableAdapter is defined incorrectly. Option Strict will either have to be turned off or you will need to change your stored procedure to return a resultset and call it using ExecuteScalar.
    Monday, July 21, 2008 3:58 PM

All replies

  • I actually found a very simple way of getting the time from the server for my application. I simply added a query in the dataset with the SQL statement: 

     

    SELECT getdate() 

     

    The query is called by default ScalarQuery. I can then use it like this in my code:

     

    Dim QTA As New localOMSDataSetTableAdapters.QueriesTableAdapter

    Dim atime As DateTime = CDate(QTA.ScalarQuery())

     

    It works fine but im still curious to know why a conversion is required. I still see the datatype ' Date? ' for the ScalarQuery function.

    Monday, July 21, 2008 3:33 PM
  • Apparently there is a narrowing conversion somewhere during the return of the call to the stored procedure, or the stored procedure parameter in the TableAdapter is defined incorrectly. Option Strict will either have to be turned off or you will need to change your stored procedure to return a resultset and call it using ExecuteScalar.
    Monday, July 21, 2008 3:58 PM