如何管理正确的代码

时间:2010-07-07 19:42:39

标签: vb.net datagridview datagrid

我有数据源和表格,我可以绑定到我的控件和datagridview。我可以添加记录到数据表,我可以在datagridview上查看,但我不能使用datagrid更新和删除记录。我有以下代码。如果有人可以帮助我,我将非常感激。

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

1 个答案:

答案 0 :(得分:0)

我开始回答自己。 :)我找到了理由。我的桌子上没有主键。我补充说,问题解决了。