2017-04-20 5 views
0

Ich stapeln bei meinem Code Ich habe eine Datagridview dann, wenn Datagridview Werte alle in meiner Tabelle bereit ist dann aktualisieren Sie meine Tabelle mit DataGridview Wert sonst einfügen in meine Tabelle. Aber ich staple bei der Aktualisierung dann den aktualisierten Wert nur einmal und füge in meine Tabelle ein, wenn die Werte nicht in meiner Tabelle fehlgeschlagen sind.vb.net Update-Tabelle mit Datagridview

Hier ist mein Tisch und Wert enter image description here

Hier mein Code

For Each row As DataGridViewRow In dgvLosshours.Rows 
If (row.Cells("losshrs").Value = "") Then 
    MsgBox("Losshours can't Empty", MsgBoxStyle.Critical) 
    Return 
Else 
    Dim i As Integer = 0 
    Dim hd As Integer = row.Cells("headcount").Value * row.Cells("workhrs").Value - row.Cells("losshrs").Value 
    Dim cmd1 As New MySqlCommand 
    Dim mydt1 As New DataSet 
    Dim myadapt1 As New MySqlDataAdapter 
    openConnectionsMySQL() 
    cmd1 = New MySqlCommand("select * from whweek where periode = date_format(NOW(), '%m-%Y') ", connectMySQL) 
    myadapt1 = New MySqlDataAdapter(cmd1) 
    myadapt1.Fill(mydt1, "list") 
    connectMySQL.Dispose() 
    If (mydt1.Tables(0).Rows.Count = 19) Then 
     Dim c As String = "Update whweek losshours : " & row.Cells("losshrs").Value & ", RegularHours :" & hd 
      With dgvLosshours 
       dt = ctrl.ActionQuery("update whweek set workhrs = '" & row.Cells("workhrs").Value & "', losshours = '" & _ 
       row.Cells("losshrs").Value & "', reghrs = '" & hd & "', Ke = '" & _ 
       row.Cells("edate").Value & "', modifyby = '" & frmMenu.toolempno.Text & _ 
       "', modifyon = '" & today & "' where CodeDept = '" & _ 
       row.Cells("dept").Value & "' and class = '" & row.Cells("class").Value & "' ") 
       dt = ctrl.ActionQuery("INSERT INTO log (EmpNo, Tanggal, Ket) VALUES ('" & frmMenu.toolempno.Text & "', '" & today & "', '" & c & "')") 
      End With 

      MsgBox("LossHours had been updated!") 
      dgvLosshours.Rows.Clear() 

    ElseIf (mydt1.Tables(0).Rows.Count = 0) Then 

     Dim hd1 As Integer = row.Cells("headcount").Value * row.Cells("workhrs").Value - row.Cells("losshrs").Value 
     Dim c As String = "Add LossHrs By :" & frmMenu.toolempno.Text & " Period : " & period 
     dt = ctrl.ActionQuery("insert into whweek(codedept, class, workhrs, losshours, reghrs, Dari, Ke, createby, createon) values('" & _ 
     row.Cells("dept").Value & _ 
     "','" & row.Cells("class").Value & _ 
     "','" & row.Cells("workhrs").Value & _ 
     "','" & row.Cells("losshrs").Value & _ 
     "','" & hd1 & "','" & _ 
     row.Cells("sdate").Value & "', '" & _ 
     row.Cells("edate").Value & "', '" & _ 
     frmMenu.toolempno.Text & "','" & today & "')") 
     dt = ctrl.ActionQuery("INSERT INTO log (EmpNo, Tanggal, Ket) VALUES ('" & _ 
     frmMenu.toolempno.Text & "', '" & today & "', '" & c & "')") 
     MsgBox("Successful Save LossHours") 
     dgvLosshours.Rows.Clear() 
    End If 

End If 

Weiter

und ich möchte das Volumen werden 100 für alle Positionen aktualisieren und ‚2017.04.26 'date2 für alle Artikel und wenn ich neu date1 und date2 starte alle Artikel werden dupliziert, ist das Volumen, Menge, Volumen * Menge Verlust Sachen date1 und date2 sind nicht die gleichen Werte

ex neue Daten einfügen meine Frage nicht zu meinem Tisch

enter image description here

Aktualisierungsdaten meinen Code aktualisieren fügen Sie einfach die erste Zeile ich will, ist Update alle Reihe.

enter image description here

meinen Code nicht zurückgeben diese beiden Bild ich will. Bitte zeigen Sie mir die Art und Weise, dank

+0

Welche Fehlermeldung erhalten Sie? Dieses Beispiel ist nicht sehr prägnant. –

+0

Hallo @DanielShillcock, tut mir leid. Ich werde diesen Beitrag editieren und zeige dir bitte den Weg –

Antwort

0

Dank i meine Antwort wissen, haben hier den Code:

update whweek set wh= '" & dgvLosshours.Rows(intI).Cells("wh").Value & "', lh= '" & _ 
             dgvLosshours.Rows(intI).Cells("lh").Value & "', reg= '" & hd & "', Ke = '" & _ 
             dgvLosshours.Rows(intI).Cells("edate").Value & "', modifyby = '" & frmMenu.no.Text & _ 
             "', modifyon = '" & today & "', periode = '" & dgvLosshours.Rows(intI).Cells("periode").Value & "' where id= '" & _ 
             dgvLosshours.Rows(intI).Cells("id").Value & "' and class = '" & dgvLosshours.Rows(intI).Cells("class").Value & _ 
             "' and Dari = '" & dateFrom.Text & "' 
Verwandte Themen