Private Sub holidaysaveButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles holidaysaveButton.Click For Each dr As DataGridViewRow In DataGridView1.Rows Dim cell1 As String Dim cell2 As Date Dim cell3 As String Dim cell4 As String = "Holiday" If dr.IsNewRow Then Exit For If dr.Cells(4).Value = "True" Then Dim str1 As String = dr.Cells(1).Value.ToString Dim str2 As String = dr.Cells(2).Value.ToString Dim str3 As String = dr.Cells(3).Value.ToString Dim str4 As String = dr.Cells(4).Value.ToString End If If dr.Cells(4).Value IsNot Nothing Then cell1 = dr.Cells(1).Value.ToString() cell2 = dr.Cells(2).Value.ToString() cell3 = dr.Cells(3).Value.ToString() Dim con As New SqlConnection Dim cmd As New SqlCommand Try con.ConnectionString = "Data Source=xxxxx;Initial Catalog=xxxxx;User ID=xxxxx;Password=xxxxx" con.Open() cmd.Connection = con cmd.CommandText = "INSERT INTO exceptions (employeenumber, exceptiondate, minutes, code) VALUES ('" & cell1 & "','" & cell2 & "','" & cell3 & "','" & cell4 & "')" cmd.ExecuteNonQuery() MessageBox.Show("Your data has been updated") Catch ex As Exception MessageBox.Show("Error while updating record on table..." & ex.Message, "Update Records") Finally con.Close() End Try End If DailySummaryReview.holidayaddButton.Enabled = False Me.Close() Next End Sub
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)