16,717
社区成员
发帖
与我相关
我的任务
分享Private Sub AddARow(dataSet As DataSet)
Dim table As DataTable = dataSet.Tables("Suppliers")
' Use the NewRow method to create a DataRow
'with the table's schema.
Dim newRow As DataRow = table.NewRow()
' Set values in the columns:
newRow("CompanyID") = "NewCompanyID"
newRow("CompanyName") = "NewCompanyName"
' Add the row to the rows collection.
table.Rows.Add(newRow)'删除就用Remove
End Sub
}'修改Dataset后重新绑定
DataGridView.Datasoure=修改后的Dataset
Sub addmdb(ByVal phonenum_a A String, ByVal pos_a As String, ByVal addr_a As String)
Dim cn As New OleDb.OleDbConnection
Dim dr As DataRow
Dim ds As New DataSet
Dim ds1 As New DataSet
Dim da As New OleDbDataAdapter
Dim str As String
Dim myDataRowsCommandBuilder As OleDbCommandBuilder = New OleDbCommandBuilder(da)
str = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & Application.StartupPath + ( "/date/1040.mdb ")
cn.ConnectionString = str
da = New OleDbDataAdapter( "select * from mokuai ", cn)
da.Fill(ds, "mokuai ")
dr = ds.Tables( "mokuai ").NewRow
dr( "phonenum ") = phonenum_a
dr( "pos ") = pos_a
dr( "addr ") = addr_a
ds.Tables( "mokuai ").Rows.Add(dr)
Dim cb As OleDbCommandBuilder
cb = New OleDbCommandBuilder(da)
da.InsertCommand = cb.GetInsertCommand
If ds.HasChanges = True Then
ds1 = ds.GetChanges
End If
Try
da.Update(ds1, "mokuai ")
ds.AcceptChanges()
Catch ex As Exception
End Try
cn.Close()
End Sub
Public Function CreateCmdsAndUpdate(ByVal connectionString As String, _
ByVal queryString As String) As DataSet
Using connection As New OleDbConnection(connectionString)
Dim adapter As New OleDbDataAdapter()
adapter.SelectCommand = New OleDbCommand(queryString, connection)
Dim builder As OleDbCommandBuilder = New OleDbCommandBuilder(adapter)
connection.Open()
Dim customers As DataSet = New DataSet
adapter.Fill(customers)
' Code to modify data in DataSet here
adapter.Update(customers)
Return customers
End Using
End Function