Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
- 'jika stat_printer = 0 Or stat_cd1 = 0 Or stat_cd2 = 0 And stat_network = ON
- 'maka kolom ttl_status = "ON"
- 'Else
- 'jika stat_printer = 1 Or stat_cd1 = 0 Or stat_cd2 = 0 And stat_network = ON
- 'maka kolom ttl_status ="OFF"
- For Each x As DataGridViewRow In DataGridView1.Rows
- If Not x.IsNewRow Then
- If x.Cells("stat_printer").Value = 0 Or x.Cells("stat_cd1").Value = 0 Or
- x.Cells("stat_cd2").Value = 0 AndAlso x.Cells("stat_network").Value = "ON" Then
- x.Cells("ttl_status").Value = "ON"
- Else
- x.Cells("ttl_status").Value = "OFF"
- End If
- End If
- Next
- Dim query, queryInsert As New System.Text.StringBuilder
- query.AppendLine("IF EXISTS (SELECT * FROM tbl_monitoring Where kd_store=@kd) ")
- query.Append("update tbl_monitoring Set")
- queryInsert.Append("Insert Into tbl_monitoring values(")
- For Each x As DataGridViewColumn In DataGridView1.Columns
- If Not x.Name = "kd_store" Then
- query.AppendFormat(" {0}=@p{1},", x.Name, x.Index)
- queryInsert.AppendFormat("@p{0},", x.Index)
- Else
- queryInsert.Append("@kd,")
- End If
- Next
- query.Length -= 1
- queryInsert.Length -= 1
- queryInsert.Append(")")
- query.AppendLine(" where kd_store = @kd ")
- query.AppendLine("Else ")
- query.Append(queryInsert.ToString)
- Using con As New SqlConnection("Server=.;Database=dummy;Trusted_Connection=True")
- Using cmd As New SqlCommand(query.ToString, con)
- Try
- con.Open()
- For Each x As DataGridViewRow In DataGridView1.Rows
- If Not x.IsNewRow Then
- cmd.Parameters.Clear()
- For Each y As DataGridViewColumn In DataGridView1.Columns
- If y.Name = "kd_store" Then
- cmd.Parameters.Add("@kd", SqlDbType.VarChar, 100).Value =
- x.Cells(y.Index).Value
- Else
- cmd.Parameters.Add("@p" & y.Index, SqlDbType.VarChar, 100).Value =
- x.Cells(y.Index).Value
- End If
- Next
- cmd.ExecuteNonQuery()
- End If
- Next
- con.Close()
- MsgBox("Done")
- Catch ex As Exception
- MsgBox(ex.ToString)
- End Try
- End Using
- End Using
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment