Hallo,
bin relativ neu im VB.Net Umfeld und habe ein Problem mit dem Einbau einer Transactionsverarbeitung.
Folgender Code erzeugt oder ändert einen Datensatz in einer Tabelle und ich weiß nicht wie ich die Transactionsverarbeitung einbauen muß. Vielleicht kann mir freundlicher Weise jemand einen Tip geben.
Gruß Klaus
Private Sub btnÄndern_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) _
Handles btnÄndern.Click
If bsArtikelSuchen.Find("ArtikelNr", Me.txtArtikelNr.Text) = -1 Then
MessageBox.Show("Artikel-Nr." & Me.txtArtikelNr.Text & " nicht" & _
"vorhanden!", "Artikel Warnhinweis!")
Exit Sub
End If
If btnÄndern.Text = "Bearbeiten" Then
posBearbeiten = bs.Position
Editieren(True)
Else 'btnÄndern.Text = "OK"
Dim sqlCmd As New System.Data.SqlClient.SqlCommand
sqlCmd.Connection = c
If Not neuerDatensatz Then 'Datensatz mit UPDATE aktualisieren
sqlCmd.CommandText = "UPDATE PosDetails SET " _
& " GANr= " & GANrVorher _
& ", ArtikelNr = '" & Me.txtArtikelNr.Text _
& "' , Anzahl = " & Replace(Me.txtAnzahl.Text, ",", ".") _
& ", Preis = " & Replace(Me.txtPreis.Text, ",", ".") _
& ", Postensumme = " & Replace((CDec(Me.txtAnzahl.Text) * _
CDec(Me.txtPreis.Text)), ",", ".") _
& " WHERE GANr = " & GANrVorher _
& " And ArtikelNr = '" & Me.txtArtikelNr.Text & "'"
Else
If Val(Me.txtAnzahl.Text) = 0 Or Val(Me.txtPreis.Text) = 0 Then
sqlCmd.CommandText = _
"INSERT INTO PosDetails( GANr," & _
"ArtikelNr, Preis, Anzahl )" _
& "VALUES( " & GANrVorher _
& ", '" & Me.txtArtikelNr.Text _
& "', '" & Replace( _
Me.txtPreis.Text, ",", ".") _
& "', '" & Replace( _
Me.txtAnzahl.Text, ",", ".") & "')"
Else
sqlCmd.CommandText = _
"INSERT INTO PosDetails( GANr, ArtikelNr, Preis," & _
"Anzahl, Postensumme )" _
& "VALUES( " & GANrVorher _
& ", '" & Me.txtArtikelNr.Text _
& "', '" & Replace(Me.txtPreis.Text, ",", ".") _
& "', '" & Replace(Me.txtAnzahl.Text, ",", ".") _
& "', '" & Replace((CDec(Me.txtAnzahl.Text) * CDec( _
Me.txtPreis.Text)), ",", ".") & "')"
End If
End If
Debug.Print(sqlCmd.CommandText)
Try
sqlCmd.Connection.Open()
sqlCmd.ExecuteNonQuery()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
sqlCmd.Connection.Close()
End Try
Laden()
If neuerDatensatz Then
bs.MoveLast()
Else
bs.Position = posBearbeiten
End If
Editieren(False)
End If
neu_rechnen()
End Sub |