2010-07-07 85 views
0

我有我可以綁定到我的控件和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 
+0

當您嘗試更新或刪除時是否出現錯誤?你有沒有得到任何答覆? – MJB 2010-07-07 19:45:29

+0

不,實際上它是從gridview中刪除,但沒有更新。 – Hakan 2010-07-07 19:54:12

回答

0

我開始給自己答案。 :)我找到了理由。我的桌子上沒有主鍵。我補充說,問題解決了。