Dim DMC_No As New List(Of Integer)
                cmd.CommandText = "SELECT MC_No FROM tbl_MainComp WHERE EquipTag=  '" & TextBox1.Text & "'"
                Using reader As OleDb.OleDbDataReader = cmd.ExecuteReader()
                    While reader.Read()
                        DMC_No.Add(reader.GetInt32(reader.GetOrdinal("MC_No")))
                    End While
                End Using



                Dim DFM_No As New List(Of Integer)

                For i = 0 To DMC_No.Count - 1
                    MessageBox.Show(DMC_No.Item(i)) 'This line to to test is there any value in array list and it get the correct value
                    cmd.CommandText = "SELECT FM_No FROM tbl_FailureMode WHERE MC_No=  " & DMC_No.Item(i) & ""
                    Using reader2 As OleDb.OleDbDataReader = cmd.ExecuteReader()
                        While reader2.Read()
                            DFM_No.Add(reader2.GetInt32(reader2.GetOrdinal("FM_No")))
                        End While
                    End Using
                    MessageBox.Show(DMC_No.Item(i))'This line to to test is there any value in array list and it get the correct value
                Next i

I think my problem is occuring at this line

cmd.CommandText = "SELECT FM_No FROM tbl_FailureMode WHERE MC_No=  " & DMC_No.Item(i) & ""

When i set the DMC_No.Item(i) value as hard code it able to run smoothly, but when i add the DMC_No.Item(i) and i check the value by using

  Dim sResult As String = String.Join(", ", DFM_No.ToArray())
                Dim str As String
                str = String.Join(",", DFM_No)

                MessageBox.Show(str)

It does not return any value

Recommended Answers

All 2 Replies

Line 11 redeclares line 1 variable???

Put a breakpoint at

cmd.CommandText = "SELECT FM_No FROM tbl_FailureMode WHERE MC_No=  " & DMC_No.Item(i) & ""

and check the value of DMC_No.Item(i) in either the watch or immediate windows. Note that you don't need the "" at the end. You can just use

cmd.CommandText = "SELECT FM_No FROM tbl_FailureMode WHERE MC_No=  " & DMC_No.Item(i)

or even

cmd.CommandText = "SELECT FM_No FROM tbl_FailureMode WHERE MC_No=  " & DMC_No(i)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.