Er spreichert den datensatz nicht

  • VB.NET

Es gibt 1 Antwort in diesem Thema. Der letzte Beitrag () ist von Lightsource.

    Er spreichert den datensatz nicht

    Hallo zusammen, ich habe ein form .. wenn ich button1 - übernehmen klicke speichert er mmir den datensatz nicht ab,
    warum nicht ? Die überpruefung klappt... wenn ich was weg lasse meckert er artig.

    hier mal den code...

    VB.NET-Quellcode

    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2. 'Felder und werte überpruefen
    3. If ComboBox2.Text = "" Or Nothing Then
    4. MsgBox(" Bitte erst eine Anrede auswählen !", MsgBoxStyle.Exclamation, "Achtung, Problem mit Inhalt im Eingabefeld Anrede !")
    5. ComboBox2.Focus()
    6. ElseIf ComboBox3.Text = "" Or Nothing Then
    7. MsgBox(" Bitte erst eine Briefanrede auswählen !", MsgBoxStyle.Exclamation, "Achtung, Problem mit Inhalt im Eingabefeld Briefanrede")
    8. ComboBox3.Focus()
    9. ElseIf ComboBox4.Text = "" Or Nothing Then
    10. MsgBox(" Bitte erst ein Land auswählen !", MsgBoxStyle.Exclamation, "Achtung, Problem mit Inhalt im Eingabefeld Land")
    11. ComboBox3.Focus()
    12. ElseIf TextBox3.Text = "" Or Nothing Then
    13. MsgBox(" Bitte erst einen Familiennamen eingben !", MsgBoxStyle.Exclamation, "Achtung, Problem mit Inhalt im Eingabefeld Briefanrede")
    14. TextBox3.Focus()
    15. ElseIf TextBox4.Text = "" Or Nothing Then
    16. MsgBox(" Bitte erst einen Straßenamen eingben !", MsgBoxStyle.Exclamation, "Achtung, Problem mit Inhalt im Eingabefeld Straßenamen")
    17. TextBox4.Focus()
    18. ElseIf ComboBox5.Text = "" Or Nothing Then
    19. MsgBox(" Bitte erst ein Bundesland auswählen !", MsgBoxStyle.Exclamation, "Achtung, Problem mit Inhalt im Eingabefeld Bundesland")
    20. ComboBox5.Focus()
    21. ElseIf TextBox5.Text = "" Or Nothing Then
    22. MsgBox(" Bitte erst eine Hausnummer eingben !", MsgBoxStyle.Exclamation, "Achtung, Problem mit Inhalt im Eingabefeld Hausnummer")
    23. TextBox5.Focus()
    24. ElseIf TextBox6.Text = "" Or Nothing Then
    25. MsgBox(" Bitte erst eine Postleitzahl eingben !", MsgBoxStyle.Exclamation, "Achtung, Problem mit Inhalt im Eingabefeld Postleitzahl")
    26. TextBox6.Focus()
    27. ElseIf TextBox7.Text = "" Or Nothing Then
    28. MsgBox(" Bitte erst einen Ortsnamen eingben !", MsgBoxStyle.Exclamation, "Achtung, Problem mit Inhalt im Eingabefeld Ortsnamen")
    29. TextBox7.Focus()
    30. ElseIf TextBox8.Text = "" Or Nothing Then
    31. MsgBox(" Bitte erst eine Telefon Vorwahl eingben !", MsgBoxStyle.Exclamation, "Achtung, Problem mit Inhalt im Eingabefeld Telefon Vorwahl")
    32. TextBox8.Focus()
    33. ElseIf TextBox9.Text = "" Or Nothing Then
    34. MsgBox(" Bitte erst eine Telefon Nummer eingben !", MsgBoxStyle.Exclamation, "Achtung, Problem mit Inhalt im Eingabefeld Telefon Nummer")
    35. TextBox9.Focus()
    36. ElseIf TextBox1.Text <> "" Then
    37. Dim tl1 As Integer = TextBox1.Text.Length
    38. If tl1 < 3 Then
    39. MsgBox(" Firmenname ist zu Kurz !", MsgBoxStyle.Exclamation, "Achtung, Problem mit Inhalt im Eingabefeld Firma")
    40. TextBox1.Focus()
    41. End If
    42. ElseIf TextBox2.Text <> "" Then
    43. Dim tl2 As Integer = TextBox2.Text.Length
    44. If tl2 < 3 Then
    45. MsgBox(" Vorname ist zu kurz !", MsgBoxStyle.Exclamation, "Achtung, Problem mit Inhalt im Eingabefeld Vorname")
    46. TextBox2.Focus()
    47. End If
    48. ElseIf TextBox3.Text <> "" Then
    49. Dim tl3 As Integer = TextBox3.Text.Length
    50. If tl3 < 3 Then
    51. MsgBox(" Zuname ist zu kurz !", MsgBoxStyle.Exclamation, "Achtung, Problem mit Inhalt im Eingabefeld Zuname")
    52. TextBox3.Focus()
    53. End If
    54. ElseIf TextBox4.Text <> "" Then
    55. Dim tl4 As Integer = TextBox4.Text.Length
    56. If tl4 < 3 Then
    57. MsgBox(" Straßenname ist zu kurz !", MsgBoxStyle.Exclamation, "Achtung, Problem mit Inhalt im Eingabefeld Straßennname")
    58. TextBox4.Focus()
    59. End If
    60. ElseIf TextBox6.Text <> "" Then
    61. Dim tl6 As Integer = TextBox6.Text.Length
    62. If tl6 < 4 Then
    63. MsgBox(" PLZ ist zu kurz !", MsgBoxStyle.Exclamation, "Achtung, Problem mit Inhalt im Eingabefeld PLZ")
    64. TextBox6.Focus()
    65. ElseIf tl6 > 5 Then
    66. MsgBox(" PLZ ist zu lang !", MsgBoxStyle.Exclamation, "Achtung, Problem mit Inhalt im Eingabefeld PLZ")
    67. TextBox6.Focus()
    68. End If
    69. ElseIf TextBox7.Text <> "" Then
    70. Dim tl7 As Integer = TextBox4.Text.Length
    71. If tl7 < 3 Then
    72. MsgBox(" Ortsname ist zu kurz !", MsgBoxStyle.Exclamation, "Achtung, Problem mit Inhalt im Eingabefeld Ortsname")
    73. TextBox7.Focus()
    74. End If
    75. ElseIf TextBox8.Text <> "" Then
    76. Dim tl8 As Integer = TextBox4.Text.Length
    77. If tl8 < 3 Then
    78. MsgBox(" Vorwahl ist zu kurz !", MsgBoxStyle.Exclamation, "Achtung, Problem mit Inhalt im Eingabefeld Vorwahl")
    79. TextBox8.Focus()
    80. End If
    81. ElseIf TextBox9.Text <> "" Then
    82. Dim tl9 As Integer = TextBox4.Text.Length
    83. If tl9 < 4 Then
    84. MsgBox(" Telefonnr ist zu kurz !", MsgBoxStyle.Exclamation, "Achtung, Problem mit Inhalt im Eingabefeld Telefonnummer")
    85. TextBox9.Focus()
    86. End If
    87. If RadioButton3.Checked = False And RadioButton4.Checked = False And RadioButton5.Checked = False And RadioButton6.Checked = False Then
    88. MsgBox("Bitte Art der Telefonnummer auswählen !", MsgBoxStyle.Exclamation, "Achtung, Problem mit Auswahl der Telefonnummern Artr")
    89. End If
    90. ElseIf TextBox10.Text <> "" Then
    91. Dim tl10 As Integer = TextBox10.Text.Length
    92. If tl10 < 10 Then
    93. MsgBox(" Emailadresse ist zu kurz !", MsgBoxStyle.Exclamation, "Achtung, Problem mit Inhalt im Eingabefeld E-Mailadresse")
    94. TextBox10.Focus()
    95. End If
    96. If TextBox10.Text.Contains("@") Then
    97. MsgBox(" Emailadresse hat kein @ Zeichen !", MsgBoxStyle.Exclamation, "Achtung, Problem mit Inhalt im Eingabefeld E-Mailadresse")
    98. TextBox10.Focus()
    99. End If
    100. Dim tvax As String = TextBox10.Text
    101. Dim tva0() = Split(tvax, "@")
    102. Dim tval As String = tva0(0).Length
    103. Dim tnal As String = tva0(1).Length
    104. Dim tld0() = Split(tvax, ".")
    105. Dim tldlwert As Integer = tld0.Count - 1
    106. Dim tld As String = tld0(tldlwert).Length
    107. If tval < 3 Then
    108. MsgBox(" Emailadresse ist vorm @ zeichen zu kurz !", MsgBoxStyle.Exclamation, "Achtung, Problem mit Inhalt im Eingabefeld E-Mailadresse")
    109. TextBox10.Focus()
    110. ElseIf tnal < 3 Then
    111. MsgBox(" Emailadresse ist nach @ zeichen zu kurz !", MsgBoxStyle.Exclamation, "Achtung, Problem mit Inhalt im Eingabefeld E-Mailadresse")
    112. TextBox10.Focus()
    113. End If
    114. If tld < 2 Then
    115. MsgBox(" die TLD-Kennung der Emailadresse ist zu kurz !", MsgBoxStyle.Exclamation, "Achtung, Problem mit Inhalt im Eingabefeld E-Mailadresse")
    116. TextBox10.Focus()
    117. End If
    118. MsgBox(" überpruefen problem ")
    119. Else
    120. MsgBox(" überpruefen abgeschlossen ") ' Die hier geht schon nicht.. grrr...
    121. 'Kundendaten Speichern
    122. 'lnr holen
    123. Dim lnr0 As Integer = 0
    124. Dim sql1 As String = "select lnr from users order by lnr desc "
    125. Dim con1 As New MySqlConnection
    126. Dim cmd1 As New MySqlCommand(sql1, con1)
    127. Dim myAdapter1 As New MySqlDataAdapter
    128. con1.ConnectionString = "server='" & dbh & "';" _
    129. & "uid='" & dbu & "';" _
    130. & "pwd='" & dbp & "';" _
    131. & "database='" & dbd & "';"
    132. Try
    133. con1.Open() ' Verbindung öffnen
    134. Catch myerror As MySqlException
    135. MsgBox("Keine Verbindung zur Datenbank : " & myerror.Message.ToString) ' Falls Fehler : Fehler anzeigen
    136. End Try
    137. Try
    138. lnr0 = cmd1.ExecuteScalar
    139. con1.Close()
    140. Catch ex As Exception
    141. MsgBox(ex.Message & " Problem neuer anlage kdnr")
    142. Finally
    143. End Try
    144. 'Anrede und geschlecht auswerten
    145. Dim selectedIndexA As Integer
    146. selectedIndexA = ComboBox1.SelectedIndex
    147. Dim selectedItemA As Object
    148. selectedItemA = ComboBox1.SelectedItem.Split("/").GetValue(0)
    149. Dim selectedItemG As Object
    150. selectedItemG = ComboBox1.SelectedItem.Split("/").GetValue(1)
    151. Dim wertA As String
    152. wertA = selectedItemA
    153. Dim wertG1 As String
    154. Dim wertG As String
    155. wertG1 = selectedItemG
    156. wertG = Replace(wertG1, " ", "")
    157. 'briefanrede auswerten
    158. Dim selectedIndexB As Integer
    159. selectedIndexB = ComboBox2.SelectedIndex
    160. Dim selectedItemB As Object
    161. selectedItemB = ComboBox2.SelectedItem.Split("/").GetValue(0)
    162. Dim wertB As String
    163. wertB = selectedItemB
    164. Dim spart As String = ""
    165. Dim felder As String = ""
    166. Dim werte As String = ""
    167. Dim insert As String = ""
    168. Dim con As New MySqlConnection
    169. Dim myAdapter As New MySqlDataAdapter
    170. con.ConnectionString = "server='" & dbh & "';" _
    171. & "uid='" & dbu & "';" _
    172. & "pwd='" & dbp & "';" _
    173. & "database='" & dbd & "';"
    174. Try
    175. con.Open() ' Verbindung öffnen
    176. con.Close()
    177. Catch myerror As MySqlException
    178. MsgBox("Keine Verbindung zur Datenbank : " & myerror.Message.ToString) ' Falls Fehler : Fehler anzeigen
    179. End Try
    180. Dim ath As String = "NULL"
    181. Dim n0 As String = "0"
    182. Dim n1 As String = ""
    183. Dim statu = "active"
    184. Dim tipe As String = "sing"
    185. Dim hkd As String = "t"
    186. Dim kart As String = "Lieferung"
    187. Dim art As String = "ku"
    188. Dim telfp As String = ""
    189. Dim telmp As String = ""
    190. Dim telff As String = ""
    191. Dim telmf As String = ""
    192. Dim emailp As String = ""
    193. Dim emailg As String = ""
    194. Dim lnr1 As String = lnr0 + 1
    195. Dim lnr As String = lnr1.ToString
    196. If tart = "fp" Then
    197. telfp = Label23.Text
    198. telmp = n1
    199. telff = n1
    200. telmf = n1
    201. emailp = TextBox10.Text
    202. emailg = n1
    203. ElseIf tart = "mp" Then
    204. telfp = n1
    205. telmp = Label23.Text
    206. telff = n1
    207. telmf = n1
    208. emailp = TextBox10.Text
    209. emailg = n1
    210. ElseIf tart = "ff" Then
    211. telfp = n1
    212. telmp = n1
    213. telff = Label23.Text
    214. telmf = n1
    215. emailp = n1
    216. emailg = TextBox10.Text
    217. ElseIf tart = "ff" Then
    218. telfp = n1
    219. telmp = n1
    220. telff = n1
    221. telmf = Label23.Text
    222. emailp = n1
    223. emailg = TextBox10.Text
    224. End If
    225. spart = "INSERT INTO users"
    226. felder = "(id,uid,auth,pwd,email,fname,lname,addr,city,state,country,zipcode,phone,datesignup,status,type,Anrede,hkd,art,kdnr,hnr,gphone,mobile,gmobile,fax,gfax,gemail,vkart,lnr,banrede,firma,geb)"
    227. ' id, uid, auth, pwd, email, fname, lname, addr, city, state, country, zipcode, phone, datesignup, status, type, Anrede, hkd, art, kdnr, hnr, gphone, mobile, gmobile, fax, gfax, gemail, vkart, lnr, banrede, firma, geb
    228. werte = "('" & Label13.Text & "','" & n0 & "'," & ath & ",'" & n0 & "','" & emailp & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox7.Text & "','" & Label22.Text & "','" & Label21.Text & "','" & TextBox6.Text & "','" & telfp & "','" & Label15.Text & "','" & statu & "','" & tipe & "','" & wertG & "','" & hkd & "','" & art & "','" & Label3.Text & "','" & TextBox5.Text & "','" & telff & "','" & telmf & "','" & telmf & "','" & n1 & "','" & n1 & "','" & emailg & "','" & kart & "','" & lnr & "','" & wertB & "','" & TextBox1.Text & "','" & n1 & "')"
    229. Dim sqls As String = "" & spart & felder & "values" & werte & ""
    230. Dim cmds As New MySqlCommand(sqls, con)
    231. Dim anzahls As Integer '= 0
    232. Try
    233. con.Open()
    234. anzahls = cmds.ExecuteNonQuery()
    235. con.Close()
    236. SP0 = "ja"
    237. MsgBox(SP0)
    238. Catch myerror As MySqlException
    239. MsgBox("Fehler bei speichern" & myerror.Message.ToString) ' Falls Fehler : Fehler anzeigen
    240. End Try
    241. End If
    242. If SP0 = "ja" Then
    243. MsgBox(" Adresse ist gespeichert ")
    244. Me.Close()
    245. End If
    246. End Sub


    thx schon mal ronaldl
    Hast du schon mal den Begriff gehört:

    Teile und herrsche!

    Das trifft jedenfalls nicht auf deinen Code zu.
    Das ist mir jetzt doch etwas mühsam, mich durch diesen Code zu quälen.
    Es wäre viel übersichtlicher, wenn du verschiedene Teile in einzelne Funktionen packen würdest.
    Dann wäre es auch für dich leichter Fehler zu finden. Setze dir ein Limit von sagen wir mal 10
    Zeilen Code für jede Funktion.
    Wenn möglich trenne die Eventhandler wie z.B. Buttonclick von den Datenbankfunktionen.
    Schreibe dir meinetwegen eine Klasse, die nur für die Datenbanksachen zuständig ist.
    Dann eine Klasse, die Eingabefehler checkt etc.