2011-05-13 76 views
0

使用Visual Studio 2010使用數據集vb.net

我想使用Windows窗體拖放數據源。

網格自動生成,導航條帶有添加,保存,刪除等少數控件。

但它在主表不工作,meanS當我想添加新的,它顯示保存,但它沒有保存在實際的數據表中。請幫助更新,插入和刪除。

Public Class Form1 

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
    'TODO: This line of code loads data into the 'Agents_DataSet.trans' table. You can move, or remove it, as needed. 
    Me.TransTableAdapter.Fill(Me.Agents_DataSet.trans) 



End Sub 


Private Sub TransBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TransBindingNavigatorSaveItem.Click 
    Me.Validate() 
    Me.TransBindingSource.EndEdit() 
    Me.TableAdapterManager.UpdateAll(Me.Agents_DataSet) 

End Sub 
+0

嗨。您是否使用Access(mdb)數據庫或SQL Express(mdf)文件作爲DataSets的數據源? – Vaibhav 2011-05-13 08:18:11

+0

感謝您的回覆,我正在使用MS Access。 – Dev 2011-05-13 10:59:00

回答

0


因爲Access不支持LINQ你必須鍵入我覺得自己的發言。
這是一個老項目的一個片段,我寫了我自己的Querys到DB。

''' <summary> 
''' ExecuteQuery - Execute the query and returns true the excecution was successful 
''' </summary> 
''' <returns></returns> 
''' <remarks></remarks> 
Public Shared Function ExecuteQuery(ByVal sQuery As String) As Boolean 
    Dim cConnection As OleDb.OleDbConnection = ConnectToAccess() 
    Try 
     Dim cmd As New OleDb.OleDbCommand(sQuery, cConnection) 
     cmd.ExecuteNonQuery() 
     Return (True) 
    Catch ex As Exception 
     Return False 
    Finally 
     If cConnection IsNot Nothing Then cConnection.Close() 
    End Try 
End Function 

編輯和這裏的OLEDB連接:

''' <summary> 
''' ConnectToAccess - Etablish conncetion to the selected access Database 
''' </summary> 
''' <returns></returns> 
''' <remarks></remarks> 
Public Shared Function ConnectToAccess() As OleDb.OleDbConnection 
    Try 
     Dim myOleDbConnection As New OleDb.OleDbConnection 
     myOleDbConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=access.mdb;Jet OLEDB:Database Password=yourPassword;") 
     myOleDbConnection.Open() 
     Return myOleDbConnection 
    Catch ex As Exception 
     MsgBox("Couldnt etablish the connection to Access. ", ex) 
     Return Nothing 
    End Try 
End Function 
+0

嗨,我也試過SQL Server!但相同的狀態 – Dev 2011-05-15 02:56:20

+0

這是用於MS Access而不是用於SQL。但msaccess的背景基於SQL。只需調用ExecuteQuery(「update tbl_example set SomeBool = True,其中pkID = 1」) – SwissGuy 2011-05-16 08:16:24

+0

非常感謝!我得到了很多東西解決,但我仍然在插入批處理datagridview記錄,如果你能幫助...請 – Dev 2011-05-16 11:19:51