Search code examples
c#sql-server-2012visual-studio-2015strongly-typed-dataset

Correct parameter types for select queries that use table valued functions


My SQL Server 2012 contains a function Get_Schedule:

CREATE FUNCTION Get_Schedule(
    @pProject_Id   AS INT,
    @pPeriod_Start AS DATETIME2,
    @pPeriod_End   AS DATETIME2)
RETURNS TABLE
WITH SCHEMABINDING
AS
    RETURN (
        SELECT
            42     AS Val1,
            'Foo'  AS Val2);

Visual Studio 2015's SQL Server Object Explorer shows the function parameters with the types as defined.

However when dragging the function to the strongly typed dataset designer the DATETIME2 parameters are changed to ANSISTRING instead of System.DateTime or System.Data.SqlDbType.DateTime2.

The int parameter, @pProject_Id does have the correct type.

This happens both when using a select statement for the table adapter to access the database and when creating new a stored procedure (the procedure itself does have the expected DATATIME2 as parameter but the generated table adapter has ansistring).

How to have the correct parameter types in the generated table adapters?


Solution

  • After adding the query and its table adapter:

    • open the table adapter's properties;
    • expand SelectCommand; and,
    • edit the Parameters tot the correct type.