none
LinqDataSource and parameters in the Where clause RRS feed

  • Question

  • When building a WhereParameter at runtime to add to a LinqDataSource, I get an operand incompatible error when the "=" equals sign can't compare a String (my parameter, with a value of "4") and a SQL int field.  Shouldn't Linq be able to do a simple conversion here to compare the string to the int in the database?

    Where clause is "BrokerGroupId = @bgid"

    Line in code that assigns the parameter is:
    LinqDataSource1.WhereParameters.Add("bgid", brokerGroupId)


    The Integer variable brokerGroupId has a value of 4.  Once the LinqDataSource control tries to retrieve the filtered data is when I get the operand incompatible error.
    Wednesday, August 20, 2008 5:35 PM

Answers

  • A little elbow grease goes a long way.  I decided to create my own parameter, and since it allows you to set the DbType this worked:

    Dim p As New Parameter("bgid", Data.DbType.Int32, brokerGroupId.ToString)
    LinqDataSource1.WhereParameters.Add(p)



    Wednesday, August 20, 2008 5:52 PM

All replies

  • A little elbow grease goes a long way.  I decided to create my own parameter, and since it allows you to set the DbType this worked:

    Dim p As New Parameter("bgid", Data.DbType.Int32, brokerGroupId.ToString)
    LinqDataSource1.WhereParameters.Add(p)



    Wednesday, August 20, 2008 5:52 PM
  • As odd as it sounds the LinqDataSource is actually part of ASP.NET and the team that is responsible for it have their own forum over at http://forums.asp.net/23.aspx

     

    That's not to say somebody here can't help - at a guess I'd try changing that line so it says:

     

    LinqDataSource1.WhereParameters.Add("bgid", Int.Parse(brokerGroupId))

     

    [)amien

     

    Wednesday, August 20, 2008 5:53 PM
    Moderator