Results 1 to 8 of 8

Thread: (Resolved) Update Database through Datagridview

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    259

    (Resolved) Update Database through Datagridview

    I am trying to update the database through my datagrid view and keep getting an error. What am I doing wrong?
    Code:
    Public Class frmMain
    
        Private Sub frmMain_Load( _
            ByVal sender As System.Object, _
            ByVal e As System.EventArgs) Handles MyBase.Load
    
            Me.daCoupons.Fill(Me.dsCoupons.tblCouponRedeptionData)
            With dgvCouponCodes
                .Columns.Item(0).HeaderText = "Coupon ID"
                .Columns.Item(0).Width = 75
                .Columns.Item(1).HeaderText = "Group"
                .Columns.Item(1).Width = 80
                .Columns.Item(2).HeaderText = "Vehicle"
                .Columns.Item(2).Width = 135
                .Columns.Item(3).HeaderText = "Distribution"
                .Columns.Item(3).Width = 70
                .Columns.Item(4).HeaderText = "Cost"
                .Columns.Item(4).Width = 70
                .Columns.Item(5).HeaderText = "Notes"
                .Columns.Item(5).Width = 225
                .Columns.Item(6).HeaderText = "In House?"
                .Columns.Item(6).Width = 75
                .Columns.Item(7).HeaderText = "Show Coupon?"
                .Columns.Item(7).Width = 85
            End With
        End Sub
    
        Private Sub btnSave_Click( _
            ByVal sender As System.Object, _
            ByVal e As System.EventArgs) Handles btnSave.Click
    
            Dim answer As Integer
            If dsCoupons.HasChanges Then
                answer = MessageBox.Show( _
                    "Confirm Update", _
                    "Update Confirmation", _
                    MessageBoxButtons.YesNo)
                If answer = vbYes Then
                    Try
                        dsCoupons.AcceptChanges()
                        daCoupons.Update(dsCoupons)
                    Catch ex As Exception
                        MessageBox.Show( _
                            ex.Message & vbNewLine & _
                            ex.Source, "Error", _
                            MessageBoxButtons.OK, _
                            MessageBoxIcon.Error)
                    End Try
                End If
            End If
        End Sub
    End Class
    Last edited by FastEddie; Jul 16th, 2007 at 03:12 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width