Need help finding a flaw in my code

Hi,

I need to look up the number of certains rows and if the number is greater than 0, I upload the database. Now in rare cases I know for a fact there are a number of rows in the database but IntAantalRB stays at 0. I can't reproduce this issue but this needs solving asap, I'm hoping someone can help me with this?

Kind regards,

MrFawlty
Dim blnTestAantal As Boolean
		IntAantalRB = 0
		Using conn As New SqlCeConnection("Data Source=\SD-MMC Card\Database.sdf;")
			Mobile.DtaDocument.Connection.ConnectionString = "Data Source=\SD-MMC Card\Database.sdf;"
			Try
				If conn.State = ConnectionState.Closed Then
					conn.Open()
				End If

				Mobile.DtaDocument.Fill(Mobile.adsMobile.DocumentRB)
				IntAantalRB = Mobile.adsMobile.DocumentRB.Rows.Count
				conn.Close()
				blnTestAantal = True
			Catch ex As Exception
				conn.Close()
				IntAantalRB = 0
			End Try
		End Using

Open in new window

MrFawltyAsked:
Who is Participating?
 
OP_ZaharinConnect With a Mentor Commented:
hi Mr.Fawlty,
- where/how do u display the IntAantalRB result? can you share with us the display module?
- do you declare IntAantalRB as Public or are you using passing variables?
- IntAantalRB = Mobile.adsMobile.DocumentRB.Rows.Count < this code already set IntAantalRB = 0 if there Rows.Count = 0. there is no need for IntAantalRB = 0 in line 16.
0
 
Mikal613Commented:
First the connection close should go in the Finally clause.

At what point in the code do you want IntAantalRB = 0? When theres an exception? Or at the end of the Try block?

                         Try
                        If conn.State = ConnectionState.Closed Then
                              conn.Open()
                        End If

                        Mobile.DtaDocument.Fill(Mobile.adsMobile.DocumentRB)
                        IntAantalRB = Mobile.adsMobile.DocumentRB.Rows.Count
                        conn.Close()
                        blnTestAantal = True
                  Catch ex As Exception
                        Finally
                        conn.Close()
                        
                  End Try
0
 
MrFawltyAuthor Commented:
I only want IntAantalRB = 0 when there are Rows.Count = 0, the problem is that in some cases I'm 100% sure Rows.Count should be > 0 but something goes wrong with retrieving this information.

I need to make 100% sure that Rows.Count is actually > 0 or = 0.

Perhaps the sdf is locked?

How can I be 100% sure I get the correct Count?

Kind regards,

MrFawlty
0
 
MrFawltyAuthor Commented:
Hi OP_Zaharin,

- I don't display the result, if Rows.Count > 0 I upload the sdf in question but in 0,5% of cases this code returns intAantalRB = 0 when it should be > 0.

- IntAantalRb is a property.

- True, overkill :(



0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.