Sandeep Mewara
Кажется, вы начали отсюда, но не следовали ему полностью: Visual Basic .NET: добавление новой записи[^] - вы должны прочитать строку за строкой и понять.
Образец, который вы можете попробовать:
Private Function CreateConnection() As OleDb.OleDbConnection
Return New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\DBCaseStudy.mdb;Persist Security Info=False")
End Function
Private Sub btnRegCreate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRegCreate.Click
Using conn As OleDb.OleDbConnection = CreateConnection()
Using comd As New OleDb.OleDbCommand("INSERT INTO tblAdmins ([ID], [Firstname], [Lastname], [Username], [Password] VALUES (@ID, @Firstname, @Lastname, @Username, @Password)", conn)
comd.Parameters.AddWithValue("@ID", txtRegID.Text)
comd.Parameters.AddWithValue("@Firstname", txtRegFirst.Text)
comd.Parameters.AddWithValue("@Lastname", txtRegLast.Text)
comd.Parameters.AddWithValue("@Username", txtRegUsername.Text)
comd.Parameters.AddWithValue("@Password", txtRegPass.Text)
conn.Open()
Try
comd.ExecuteNonQuery()
MsgBox("Record Appended", MsgBoxStyle.Information, "Successfully Added!")
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Using
End Using
End Sub
ОБНОВЛЕНИЕ:
Для конкретного commandbuilder:
Объект dataadapter с помощью метода commandbuilder - oledb для[
^]
Imports System.Data.OleDb
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim connetionString As String
Dim connection As OleDbConnection
Dim oledbAdapter As OleDbDataAdapter
Dim oledbCmdBuilder As OleDbCommandBuilder
Dim ds As New DataSet
Dim i As Integer
Dim sql As String
connetionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Your mdb filename;"
connection = New OleDbConnection(connetionString)
sql = "select * from tblUsers"
Try
connection.Open()
oledbAdapter = New OleDbDataAdapter(sql, connection)
oledbCmdBuilder = New OleDbCommandBuilder(oledbAdapter)
oledbAdapter.Fill(ds)
For i = 0 To ds.Tables(0).Rows.Count - 1
ds.Tables(0).Rows(i).Item(2) = "neweamil@email.com"
Next
oledbAdapter.Update(ds.Tables(0))
connection.Close()
MsgBox("Email address updates !")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
End Class