How does the dataset constructor determine the type of scalar query return?

I am trying to add a scalar query to a dataset. The query is pretty straight forward, it just adds some decimal values ​​to several columns and returns them. I am 100% sure that only one row and one column are returned and that it has a decimal type (SQL money type). The problem is that, for some reason, the generated method (in the .designer.cs code file) returns an object type value when it should be decimal. It is strange that there is another scalar query that has the same SQL, but returns a decimal value, as it should be.

How does a data set designer define a data type and how can I say that it returns a decimal number?

+3
source share
2 answers

Instead of using a scalar stored procedure, use a scalar function instead. The dataset designer will correctly determine the data type for the scalar function. You only need to use the scalar stored procedure if you make changes to the data during the request. The scalar function is read-only. You can also very conveniently drag a function into your dataset as a query instead of going through the wizard.

If you insist on using a stored procedure or a regular query, you can always do your result like this (in VB) ...

    Dim ta As New DataSet1TableAdapters.QueriesTableAdapter
    Dim result As Decimal = DirectCast(ta.StoredProcedure1, Decimal)

or with the option Infer On

    Dim resultInfer = DirectCast(ta.StoredProcedure1, Decimal)
+1
source

dataset.tables( ") " schematype.source", dataadapters. : sqladp.fillschema(ds.tables(0), schematype.source)

sqladp.fill(ds.tables(0))

, .

?

0

Source: https://habr.com/ru/post/1741138/


All Articles