none
Sequence contains more than one element error RRS feed

  • Question

  • Hi everybody,

    I'm trying the following piece of code

    string commandText = String.Format("select top (1) * from dbo.{0} where {1} = @PrimaryKey for xml path(''), elements absent ;", tableName, primaryKeyName);
                    SqlParameter primaryKey = new SqlParameter("@PrimaryKey", SqlDbType.Decimal, 17);
                    primaryKey.Value = (Decimal) id;
                    originalState = _siriusContext.CoreContext.ExecuteStoreQuery<String>(commandText, primaryKey).Single().ToString();

    and getting the error from the title back. The SQL statement returns a single row with a string. I need to get back this string and wondering what would be the correct solution for my problem.

    Do I need to declare result as IEnumerable<String> instead and try to get the result this way?

    Thanks a lot in advance.


    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog


    My TechNet articles

    Monday, July 13, 2015 10:38 PM

Answers

  • I solved the problem by getting the result (without single) into another variable and looping through it and constructing my string this way.

    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog


    My TechNet articles

    • Marked as answer by Naomi N Tuesday, July 14, 2015 6:25 PM
    Tuesday, July 14, 2015 6:25 PM

All replies

  • I solved the problem by getting the result (without single) into another variable and looping through it and constructing my string this way.

    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog


    My TechNet articles

    • Marked as answer by Naomi N Tuesday, July 14, 2015 6:25 PM
    Tuesday, July 14, 2015 6:25 PM
  • It is glad to hear that you got it working and thank you for sharing your solutions & experience here. It will be very beneficial for other community members who have similar questions.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, July 15, 2015 1:52 AM
    Moderator