0

I'm trying to put to array my SQL query string but I encounter this error

An unhandled exception of type 'System.NullReferenceException' occurred

What is the possible problem I have?

Dim myList As ArrayList
Dim cnt As Integer
cnt = lvTrans.SelectedItems.Count
For values As Integer = 0 To cnt
    Dim vals1 = lvTrans.FocusedItem.SubItems(9).Text()
    sqlString2 = " UNION " & _
    "SELECT * FROM tbltransmital_mkk t INNER JOIN tbltransmital1_mkk t1 ON t.transmital_no = t1.transmital_no WHERE t.transmital_no='" & txtTrans.Text & _
    "' AND t1.autokey ='" & vals1 & "'"
    myList.Add(sqlString2)

Next
sqlString = sqlString1 & sqlString2
MsgBox(sqlString)

1 Answer 1

1

myList is Nothing. You never create an instance (with New).

As there's no reason to use an ArrayList at all (except you're somehow forced to work with .Net 1.1 or something), better use a List(Of String) instead, e.g.:

Dim myList = New List(Of String) ' <-- create an instance with "New"
Sign up to request clarification or add additional context in comments.

5 Comments

how can i get the value from array?
I don't know exactly what how can i get the value from array is supposed to mean but I guess you want to combine sqlString1 with the bunch of UNION clauses you add to myList. You can do something like sqlString = sqlString1 & String.Join(" ", myList).
yeah exactly :) im using visual basic 2003, New List(Of String) & String.Join(" ", myList) doesn't work for me.
What a pity. But you can use new ArrayList and String.Join(" ", myList.ToArray()).
An unhandled exception of type 'System.InvalidCastException' occurred another error LOL

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.