vb.net中如何把DataGridView当前行的值跟新到ACCESS数据库

 我来答
uouo99
2011-05-04 · TA获得超过561个赞
知道小有建树答主
回答量:655
采纳率:0%
帮助的人:348万
展开全部
参考一下下面这段代码:
Imports System.Data.OleDb
Public Class Form1
Dim SqlCOM As OleDbConnection
Dim SqlUse As OleDbDataAdapter
Dim Dt As DataSet
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
'连接数据库
SqlCOM = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\LP\Documents\Database1.accdb")

'执行数据命令获取表
SqlUse = New OleDbDataAdapter("SELECT * FROM 表1", SqlCOM)

Dt = New DataSet
SqlUse.Fill(Dt) '放入dataset中
Catch
MsgBox(Err.Description, 48)
End Try
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
DataGridView1.DataSource = Dt.Tables(0).DefaultView 'DVG与DADASET同步数据显示
Catch
MsgBox(Err.Description, 32)
End Try
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Try
Dim ass As New OleDbCommandBuilder(SqlUse) '关联DataSet和数据库的操作(更新)
SqlUse.UpdateCommand = ass.GetUpdateCommand() '执行更新所需的 OleDbCommand 对象
SqlUse.Update(Dt.Tables(0)) '执行OleDbDataAdapter的Update更新数据库
Catch
MsgBox(Err.Description, 32)
Finally
MsgBox("更新成功", 64)
End Try
End Sub
End Class
匿名用户
2011-05-05
展开全部
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cstring As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\db.mdb"
Dim con As New OleDb.OleDbConnection(cstring)

Dim sql As String = "select max(字段名) from 表名"
con.Open()
Dim cmd As New OleDb.OleDbCommand(sql, con)
Dim myreader As OleDbDataReader = cmd.ExecuteReader
myreader.Read
TextBox1.Text = myreader(0)
con.Close()

End Sub
另外,虚机团上产品团购,超级便宜
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式