|
-
Aug 27th, 2012, 09:59 PM
#1
Thread Starter
Hyperactive Member
Loop stop un-expected
My loop always stop when encounter a False return
What I expect is to run other code block if False is return
The loop stop whem False is return form this
If isReg(dr(1).ToString(), dr(2).ToString().Substring(6, 5)) = True Then
When False return, the code in Else block mus be run before going to Next item on my Reader.
But my codes seems correct..I can't find where that error came from.
But my suspect is this,
Code:
If Not sendRequest(dr(1).ToString(), generateRequest(dr(2).ToString().Substring(6, 5), dr(2).ToString().Substring(11, 7), dr(2).ToString().Substring(19, 3))) Then
'if false, do something before going to Next
End If
Code:
Private Sub loopRequestedCode()
Dim da As New MySqlDataAdapter()
Dim ds As New DataSet()
Dim dt As DataTable
Dim dr As DataRow
Dim conn As MySqlConnection = New MySqlConnection()
Try
conn.ConnectionString = clsComm.connString()
Dim SQL As String = "SELECT * from tbl_request"
conn.Open()
da.SelectCommand = New MySqlCommand(SQL, conn)
Dim myCB As New MySqlCommandBuilder(da)
da.Fill(ds, "Request")
dt = ds.Tables(0)
For Each dr In dt.Rows
If isMatch(dr(2).ToString()) = True Then
If isReg(dr(1).ToString(), dr(2).ToString().Substring(6, 5)) = True Then
If Not sendRequest(dr(1).ToString(), generateRequest(dr(2).ToString().Substring(6, 5), dr(2).ToString().Substring(11, 7), dr(2).ToString().Substring(19, 3))) Then
'if false, do something before going to Next
End If
Else
If Not sendRequest(dr(1).ToString(), notReg) Then
'if false, do something before going to Next
End If
End If
Else
If Not sendRequest(dr(1).ToString(), invalidReq) Then
'if false, do something before going to Next
End If
End If
Next
ds.Dispose()
conn.Close()
Catch ex As Exception
'TODO: catch error here
Finally
conn.Close()
End Try
End Sub
Code:
Private Function isReg(ByVal sender As String, ByVal sID As String) As Boolean
Dim MyDA As New MySqlDataAdapter()
Dim MyDS As New DataSet()
Dim conn As MySqlConnection
conn = New MySqlConnection()
conn.ConnectionString = clsComm.connString()
Dim SQL As String = "SELECT * from tbl_tableS WHERE stID='" + sID + "'"
conn.Open()
MyDA.SelectCommand = New MySqlCommand(SQL, conn)
Dim cb As New MySqlCommandBuilder(MyDA)
MyDA.Fill(MyDS, "isReg")
If MyDS.Tables Is Nothing Then
Return False
Else
Dim dt As DataRow = MyDS.Tables(0).Rows(0)
Dim fromSender As String = sender.Remove(0, 3)
Dim fromDB As String = dt(7).ToString().Remove(0, 1)
If (fromSender.Equals(fromDB)) = True Then
Return True
Else
Return False
End If
End If
conn.Close()
End Function
VB 6.0 = "Self-Study" Then
vb.NET = "Self-Study" Then
C# = 'on going study.....
-
Aug 27th, 2012, 10:13 PM
#2
Re: Loop stop un-expected
The most likely reason that an exception is being thrown. Put some sensible code in your Catch block and you will find out whether that is true and, if it is, exactly what went wrong and where.
-
Aug 27th, 2012, 10:43 PM
#3
Thread Starter
Hyperactive Member
Re: Loop stop un-expected
I found it
error came from this Function isReg()
that function throw an error which IndexOutOfRange: There is nor Row at position 0
Coz values forwarded was not found on database.
Hmmm...I'm thinking what's the best approach to that issue now.
Last edited by dr_aybyd; Aug 27th, 2012 at 11:04 PM.
VB 6.0 = "Self-Study" Then
vb.NET = "Self-Study" Then
C# = 'on going study.....
-
Aug 27th, 2012, 10:52 PM
#4
Re: Loop stop un-expected
The obvious approach would be to check whether there are rows before trying to use them.
-
Aug 27th, 2012, 11:05 PM
#5
Thread Starter
Hyperactive Member
Re: Loop stop un-expected
 Originally Posted by jmcilhinney
The obvious approach would be to check whether there are rows before trying to use them.
Yeah that's what I'm doing now..I put code block to check if HasRows
VB 6.0 = "Self-Study" Then
vb.NET = "Self-Study" Then
C# = 'on going study.....
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|