views:

29

answers:

1

I have data source and table that I can bind to my controls and datagridview. I can add records to data table and i can view on datagridview but I can't update and Delete records using datagrid. I have following code. If someone can help me i will be really appreciated.

Private Sub add_and_update()
        Dim con As VistaDBConnection
        Dim Cmd As New VistaDBCommand
        Dim constring As String
        constring = String.Format("Data Source =v_slot_database.vdb3", (System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)))
        con = New VistaDBConnection(constring)
        con.Open()
        Dim metertable As DataTable = Me.DataSet1.Tables.Item("tbl_meter")
        Dim row As DataRow = metertable.NewRow()
        row.Item("CDate") = txtdate.Text
        row.Item("Machine_No") = txtno.Text
        row.Item("Turnover") = txtturnover.Text
        row.Item("Total Win") = txttotalwin.Text
        row.Item("Games Played") = txtgamesplayed.Text
        row.Item("Credit In") = txtcreditin.Text
        row.Item("Bill In") = txtbillin.Text
        row.Item("Cancel Credit") = txthandpay.Text
        metertable.Rows.Add(row)
        Me.DataSet1.tbl_meter.AcceptChanges()
        Me.Tbl_meterTableAdapter.Update(Me.DataSet1.tbl_meter)
        clear_fields()
        con.Close()
        con = Nothing
    End Sub

 Private Sub clear_fields()
        Me.txtno.Text = "0"
        Me.txtturnover.Text = "0"
        Me.txttotalwin.Text = "0"
        Me.txtgamesplayed.Text = "0"
        Me.txtcreditin.Text = "0"
        Me.txtbillin.Text = "0"
        Me.txthandpay.Text = "0"
        Me.txtno.Focus()
    End Sub
A: 

I start to give answer to myself. :) I found reason. There was no primary key on my tables. I added and the problem is solved.

Hakan