Private Sub btn_update_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_update.Click
Dim str As String = ""
Dim oCol As Integer
If oCn.State = ConnectionState.Closed Then
oCn.Open()
End If
str = "Update " & Me.ComboBox1.SelectedItem.ToString & " Set "
While (oCol <> Me.DataGridView1.Columns.Count)
str = str & Me.DataGridView1.Columns(oCol).HeaderText & "='" & Me.DataGridView1.Item(oCol, Me.DataGridView1.CurrentRow.Index).Value & "',"
oCol = oCol + 1
End While
oCol = 0
str = str.Remove(str.LastIndexOf(","), 1) & " where " & Me.DataGridView1.Columns(0).HeaderText & "=" & Me.DataGridView1.CurrentRow.Cells(0).Value
Dim cmd As New SqlClient.SqlCommand(str, oCn)
cmd.ExecuteNonQuery()
MsgBox("Record Updated")
oCn.Close()
End Sub
Private Sub btn_delete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_delete.Click
If Me.DataGridView1.SelectedRows.Count > 0 Then
If oCn.State = ConnectionState.Closed Then
oCn.Open()
End If
Dim cmd As New SqlClient.SqlCommand("Delete from " & Me.ComboBox1.SelectedItem.ToString & " where " & Me.DataGridView1.Columns(0).HeaderText & "=" & Me.DataGridView1.SelectedRows(0).Cells(0).Value, oCn)
cmd.ExecuteNonQuery()
MsgBox("Recodrd Deleted!")
oCn.Close()
End If
End Sub
Private Sub btn_save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_save.Click
Dim str As String = ""
Dim oCol As Integer
If oCn.State = ConnectionState.Closed Then
oCn.Open()
End If
str = "Insert Into " & Me.ComboBox1.SelectedItem.ToString & "("
While (oCol <> Me.DataGridView1.Columns.Count)
str = str & Me.DataGridView1.Columns(oCol).HeaderText & ","
oCol = oCol + 1
End While
oCol = 0
str = str.Remove(str.LastIndexOf(","), 1) & ") Values('"
While (oCol <> Me.DataGridView1.Columns.Count)
str = str & Me.DataGridView1.Item(oCol, Me.DataGridView1.CurrentRow.Index).Value & "','"
oCol = oCol + 1
End While
str = str.Remove(str.LastIndexOf("','"), 3) & "')"
Dim cmd As New SqlClient.SqlCommand(str, oCn)
cmd.ExecuteNonQuery()
MsgBox("Record Saved")
oCn.Close()
End Sub