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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
OP_ZaharinCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Smartphone Programming

From novice to tech pro — start learning today.