if the value havent got the table error

  • Hello People,

    I have made following code.

    my problem is the loop stops if the table doesn't exists,

    Private Sub GetOrderNR()

    Dim CompanyID(5) As String

    CompanyID = Company.SelectedItem.ToString().Split("-")

    SQL.ExecQuery(String.Format("SELECT ordernr as 'myOrdernr' FROM [myDB].Main.myOrders as tt where Companynr={0}", CompanyID(1).Trim()))

    ' CLEAR COMBOBOX

    OrderNR.Items.Clear()

    ' MsgBox(SQL.Exception)

    If SQL.RecordCount > 0 Then

    For Each r As DataRow In SQL.SQLDS.Tables(0).Rows

    OrderNR.Items.Add(r(0))

    Next

    'SET THE COMBOBOX TO THE FIRST RECORD

    OrderNR.SelectedIndex = 0

    ElseIf SQL.Exception <> "" Then

    'REPORT ERRORS

    MsgBox(SQL.Exception)

    End If

    End Sub

    I want the loop to continue instead either alert an msgbox

    Could someone help me?

    Thank you in advance

  • Your posting in the wrong forum i think , this is pure Vb.Net

    https://msdn.microsoft.com/en-us/library/ms228598%28v=vs.90%29.aspx

    the above link should work in creating a loop , you simply need to remove the message block from you code,

    try VB.net forum or C# forum instead

    Jayanth Kurup[/url]

  • you are correct sorry.

  • this is solved

    If SQL.RecordCount > 0 Then

    If SQL.SQLDS.Tables.Count > 0 Then

    For Each r As DataRow In SQL.SQLDS.Tables(0).Rows

    OrderNR.Items.Add(r(0))

    Next

    OrderNR.SelectedIndex = 0

    End If

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply