How can I retrieve a list of parameters from a stored procedure in SQL Server

后端 未结 8 1110
慢半拍i
慢半拍i 2020-11-28 12:14

Using C# and System.Data.SqlClient, is there a way to retrieve a list of parameters that belong to a stored procedure on a SQL Server before I actually execute it?

I

8条回答
  •  孤城傲影
    2020-11-28 12:48

    I have been using DeriveParameters with .NET 1.1 and 2.0 since a couple of years now, and worked like a charm every time.

    Now I'm working on my first assignment with .NET 3.5, and just found and ugly surprise: DeriveParameters is creating all parameters with SqlDbType "Variant", instead proper SqlDbTypes. This is creating a SqlException when trying to execute SPs with numeric parameters, because SQL Server 2005 says that sql-variant types cant be implictily converted to int (or smallint, or numeric) values.

    I just tested the same code with .NET CF 2.0 and SQL Server 2000, and worked as expected, assigning the correct SqlDbType to each parameters.

    I had tested .NET 2.0 apps against SQL Server 2005 Databases, so is not a SQL Server related issue, so it has to be something related with .NET 3.5

    Any ideas?

提交回复
热议问题