VB.NET操作ACCESS数据库的问题 20
我需要用OleDBDataAdapter和DataSet修改Access数据库里的记录数据库路径D:\Mydatabase.accdb数据表名:TestTable表结构(...
我需要用OleDBDataAdapter 和 DataSet 修改 Access数据库里的记录
数据库路径 D:\Mydatabase.accdb
数据表名:TestTable
表结构(字段):Indexs (文本型、主键), Titles (文本型) Details (文本型)
如何才能修改表中的数据?(例如把Details字段的值都修改为“测试修改成功”)?
下面是我写的代码:请帮忙修改
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 p_DBcnn1 As New OleDbConnection
Dim p_DBadapter1 As New OleDbDataAdapter
Dim p_DBcmd1 As New OleDbCommand
Dim p_DBset1 As New DataSet
p_DBcnn1.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\mydatabase.accdb;"
p_DBcnn1.Open()
p_DBcmd1.Connection = p_DBcnn1
p_DBcmd1.CommandText = "select * from TestTable"
p_DBadapter1.SelectCommand = p_DBcmd1
p_DBadapter1.Fill(p_DBset1)
Dim DBrow1 As DataRow
For Each DBrow1 In p_DBset1.Tables(0).Rows
DBrow1.Item("details") = "测试修改成功"
Next
p_DBadapter1.Update(p_DBset1)
p_DBcnn1.Close()
MessageBox.Show("OK")
End Sub
End Class 展开
数据库路径 D:\Mydatabase.accdb
数据表名:TestTable
表结构(字段):Indexs (文本型、主键), Titles (文本型) Details (文本型)
如何才能修改表中的数据?(例如把Details字段的值都修改为“测试修改成功”)?
下面是我写的代码:请帮忙修改
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 p_DBcnn1 As New OleDbConnection
Dim p_DBadapter1 As New OleDbDataAdapter
Dim p_DBcmd1 As New OleDbCommand
Dim p_DBset1 As New DataSet
p_DBcnn1.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\mydatabase.accdb;"
p_DBcnn1.Open()
p_DBcmd1.Connection = p_DBcnn1
p_DBcmd1.CommandText = "select * from TestTable"
p_DBadapter1.SelectCommand = p_DBcmd1
p_DBadapter1.Fill(p_DBset1)
Dim DBrow1 As DataRow
For Each DBrow1 In p_DBset1.Tables(0).Rows
DBrow1.Item("details") = "测试修改成功"
Next
p_DBadapter1.Update(p_DBset1)
p_DBcnn1.Close()
MessageBox.Show("OK")
End Sub
End Class 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询