Domanda

We have this query for a strongly typed DataSet which as created in the Visual Studio DataSet Designer:

SELECT ID, PaymentAmount, PaymentDate, WhatWasPaymentFor
  FROM Payments
 WHERE ParentID = @ParentID
   AND (@PaymentDate is null OR PaymentDate = @PaymentDate)
   AND (@PaymentAmount is null OR PaymentAmount = @PaymentAmount)
   AND ((@SearchValue is null OR 
       (WhatWasPaymentFor LIKE '%' + @SearchValue  + '%' OR @SearchValue='ALL'))
       )

In a VB.Net code-behind file we call the query to fill the DataSet like this:

Dim tblObject = theTableAdapter.GetDataByAllInOne(dcmParentsId, Nothing, Nothing, TextBoxSearch.Text)

Intellisense shows the 4th parameter as being a Decimal when I thought it would be a String. I found this out when the mouse is over the parameter for @SearchValue.

When this coding is executed, this error is displayed:

Conversion from string "Books" to type 'Decimal' is not valid.

The only column in this query that is a Decimal is PaymentAmount which happens to be the 3rd parameter not the 4th one.

I'm not sure why intellisense states that the 4th parameter @SearchValue is a Decimal. Can you show me how to change it to a String?

An interest thing that does happen is that the query will work ok if run in the SQL Server Magagement Studio as:

DECLARE @SearchValue VARCHAR = 'Books'
DECLARE @ParentID    INT = 3
DECLARE @PaymentDate DATETIME = NULL
DECLARE @PaymentAmount MONEY = NULL

SELECT ID, PaymentAmount, PaymentDate, WhatWasPaymentFor
  FROM Payments
 WHERE ParentID = @ParentID
   AND (@PaymentDate is null OR PaymentDate = @PaymentDate)
   AND (@PaymentAmount is null OR PaymentAmount = @PaymentAmount)
   AND ((@SearchValue is null OR 
    (WhatWasPaymentFor LIKE '%' + @SearchValue  + '%' OR @SearchValue='ALL'))
       )

Maybe there is something that needs to be set in the DataSet designer I'm not aware of.

È stato utile?

Soluzione

In the designer, the query will display the parameters it expects in the order it expects them ie you should see something like GetDataByAllInOne(@ParentID,@PaymentDate,@PaymentAmount,@SearchValue). Can you check this first?

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top