0

I am new in Linq. The error(conversion from string "SYMBOL" to type integer is not valid) comes in the line : ' r("SYMBOL") = q!SYMBOL.ToString'. Please help

Dim tblBhavNSEFO As DataTable = gbl_dsBhavNSEFO.Tables(0)
Dim tblSource As New DataTable
tblSource.Columns.Add("SYMBOL", GetType(String))

Dim tblsymbols As DataTable = (From s In tblBhavNSEFO _
                       Where s!INSTRUMENT = strCondition _
                       Order By s!SYMBOL Ascending _
                       Select s).CopyToDataTable
Dim filter = From f In tblsymbols _
           Select f!SYMBOL Distinct

If filter.Count > 0 Then
    For Each q In filter
        Dim r = tblSource.NewRow()
        r("SYMBOL") = q!SYMBOL.ToString
        tblSource.Rows.Add(r)
    Next
6
  • I'm pretty sure that this code does not even compile with Option Strict On... Anyway, the problem seems to be that there is one !SYMBOL too many (you already reduce to !SYMBOL in filter). Commented May 2, 2014 at 5:43
  • I just want the "SYMBOL" field of table tblbhavnsefo to be distinct and then store all the records into new table with same field name. If there mistake in code then please modify Commented May 2, 2014 at 5:51
  • 1
    filter already reduces your list of datarows to a list of whatever-datatype-symbol-is. In other words: q already contains your symbol, not a datarow, so there's no need to !SYMBOL it. Commented May 2, 2014 at 6:13
  • Yes u were right. Thanks a lot. It is working now without writing !SYMBOL. Thanks again Commented May 2, 2014 at 7:15
  • That's good to know! I added the conclusion as an answer, so that the question can be marked as answered. Commented May 2, 2014 at 8:08

1 Answer 1

1

The loop variable q already contains the symbol (you projected on f!SYMBOL in the definition of filter). Thus, adding !SYMBOL to q is not necessary.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.