login  Naam:   Wachtwoord: 
Registreer je!
 Forum

Foutmelding word steeds bij elkaar opgeteld (Opgelost)

Offline rredspike1 - 01/11/2008 03:09 (laatste wijziging 01/11/2008 03:09)
Avatar van rredspike1Lid Zie code

  1. Private Sub btnNieuweKlantToevoegen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNieuweKlantToevoegen.Click
  2. Dim oConString2 As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|MSP.mdb;"
  3. Dim oCon2 As New OleDb.OleDbConnection(oConString2)
  4.  
  5. Dim sqlBedrijfsnaam_Contactpersoon_bestaat As String = "SELECT COUNT(*) FROM Klanten WHERE Bedrijfsnaam = '" & Me.txtBedrijfsnaam_Klanten.Text & "' AND Contactpersoon = '" & Me.txtContactpersoon_Klanten.Text & "'"
  6. Dim oCmdBedrijfsnaam_Contactpersoon_bestaat As New OleDbCommand(sqlBedrijfsnaam_Contactpersoon_bestaat, oCon2)
  7.  
  8. If String.IsNullOrEmpty(txtBedrijfsnaam_Klanten.Text) Then
  9. strErrors &= "- Er is geen bedrijfsnaam ingevuld!" & Environment.NewLine
  10. xErrors = xErrors + 1
  11. End If
  12. If String.IsNullOrEmpty(txtContactpersoon_Klanten.Text) Then
  13. strErrors &= "- Er is geen contactpersoon ingevuld!" & Environment.NewLine
  14. xErrors = xErrors + 1
  15. End If
  16. If String.IsNullOrEmpty(txtAdres_Klanten.Text) Then
  17. strErrors &= "- Er is geen adres ingevuld!" & Environment.NewLine
  18. xErrors = xErrors + 1
  19. End If
  20. If String.IsNullOrEmpty(txtPostcode_Klanten.Text) Then
  21. strErrors &= "- Er is geen postcode ingevuld!" & Environment.NewLine
  22. xErrors = xErrors + 1
  23. End If
  24. If String.IsNullOrEmpty(txtPlaats_Klanten.Text) Then
  25. strErrors &= "- Er is geen plaats ingevuld!" & Environment.NewLine
  26. xErrors = xErrors + 1
  27. End If
  28. If String.IsNullOrEmpty(txtTelefoonnummer_Klanten.Text) Then
  29. strErrors &= "- Er is geen telefoonnummer ingevuld!" & Environment.NewLine
  30. xErrors = xErrors + 1
  31. End If
  32. If String.IsNullOrEmpty(txtEmailadres_Klanten.Text) Then
  33. strErrors &= "- Er is geen emailadres ingevuld!" & Environment.NewLine
  34. xErrors = xErrors + 1
  35. End If
  36.  
  37. Try
  38. oCon2.Open()
  39. Dim oReaderBedrijfsnaam_Contactpersoon_Bestaat As OleDbDataReader = oCmdBedrijfsnaam_Contactpersoon_bestaat.ExecuteReader
  40. oReaderBedrijfsnaam_Contactpersoon_Bestaat.Read()
  41. If (oReaderBedrijfsnaam_Contactpersoon_Bestaat(0) > 0) Then
  42. strErrors &= "- Bedrijfsnaam bestaat al!" & Environment.NewLine
  43. xErrors = xErrors + 1
  44. End If
  45. If (oReaderBedrijfsnaam_Contactpersoon_Bestaat(0) > 0) Then
  46. strErrors &= "- Contactpersoon bestaat al!" & Environment.NewLine
  47. xErrors = xErrors + 1
  48. End If
  49.  
  50. 'Alle errors bij elkaar optellen en weergeven'
  51. If xErrors > 0 Then
  52. MessageBox.Show(strErrors, "Fout", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  53. If Windows.Forms.DialogResult.OK Then
  54. xErrors = 0
  55. End If
  56. Else
  57. 'insert into database
  58. Dim sSQL As String = "INSERT INTO Klanten(Bedrijfsnaam, Contactpersoon, Adres, Postcode, Plaats, Telefoonnummer, Faxnummer, Emailadres) VALUES('" & Me.txtBedrijfsnaam_Klanten.Text & "', '" & Me.txtContactpersoon_Klanten.Text & "', '" & Me.txtAdres_Klanten.Text & "', '" & Me.txtPostcode_Klanten.Text & "', '" & Me.txtPlaats_Klanten.Text & "', '" & Me.txtTelefoonnummer_Klanten.Text & "', '" & Me.txtFaxnummer_Klanten.Text & "', '" & Me.txtEmailadres_Klanten.Text & "')"
  59. Dim oCom As New OleDbCommand(sSQL, oCon2)
  60.  
  61. Try
  62. oCom.ExecuteNonQuery()
  63. Catch ex As Exception
  64. MsgBox(ex.Message)
  65. Finally
  66. oCom.Dispose()
  67. oCon2.Dispose()
  68. oCon2.Close()
  69. End Try
  70. End If
  71.  
  72. oCmdBedrijfsnaam_Contactpersoon_bestaat.Dispose()
  73. Catch ex As Exception
  74. MessageBox.Show(ex.ToString)
  75. Finally
  76. oCon2.Close()
  77. oCon2.Dispose()
  78. End Try
  79. End Sub
  80. End Class


Telkens als ik een foutmelding krijg, dan de eerste keer zie ik bijvoorbeeld:
- fout nr 1
- fout nr 2
- etc..

Heb ik op OK gedrukt, en daarna op toevoegen, dat het weer een fout controle doet, krijg ik het volgende:
- fout nr 1
- fout nr 2
- fout nr 1
- fout nr 2

Zo gaat dat maar door...op een gegeven moment heb ik me een lijst...waarom zet dat ding...die integer niet op 0?
Staat er toch echt.

2 antwoorden

Gesponsorde links
Offline Abbas - 01/11/2008 03:16 (laatste wijziging 01/11/2008 03:19)
Avatar van Abbas Gouden medaille

Crew .NET
Nu is de structuur in je code al veel logischer! Zet die integer is op 0 en die string terug leeg elke keer als je op de knop klikt, en niet in een If-statement. Zoiets:
  1. 'Button Click
  2. ' xErrors = 0
  3. ' strErrors = ""
  4. ' Controle
  5. ' DB Werk
  6. 'Einde Button Click
Offline rredspike1 - 01/11/2008 03:25 (laatste wijziging 01/11/2008 04:18)
Avatar van rredspike1 Lid Yeah

Het is die strErrors = ""

Bedankt 

Had eerst:
  1. If xErrors > 0 Then
  2. MessageBox.Show(strErrors, "Fout", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  3. If Windows.Forms.DialogResult.OK Then
  4. xErrors = 0
  5. End If
  6. End If


Heb nu:
  1. If xErrors > 0 Then
  2. MessageBox.Show(strErrors, "Fout", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  3. xErrors = 0
  4. strErrors = ""
  5. End If
Gesponsorde links
Dit onderwerp is gesloten.
Actieve forumberichten
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.271s