Correct parameter types for select queries that use table valued functions

可紊 提交于 2020-01-06 20:18:09

问题


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?


回答1:


After adding the query and its table adapter:

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


来源:https://stackoverflow.com/questions/33888920/correct-parameter-types-for-select-queries-that-use-table-valued-functions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!