Link to home
Start Free TrialLog in
Avatar of MrFawlty
MrFawltyFlag for Belgium

asked on

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

Avatar of Mikal613
Mikal613
Flag of United States of America image

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
Avatar of MrFawlty

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of OP_Zaharin
OP_Zaharin
Flag of Malaysia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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 :(