VB.NET用UpdateCommand更新数据库

2024-12-28 21:54:54
推荐回答(1个)
回答1:

Try
objconn.Open()
Dim dt As New DataTable
Dim strsql = "select * from Info"
objadap.SelectCommand = New OleDb.OleDbCommand(strsql, objconn)
objadap.Fill(objDSet, "Info")
objDSet.Clear()
Dim cmdbuilder As New OleDb.OleDbCommandBuilder(objadap)
objadap.UpdateCommand = cmdbuilder.GetUpdateCommand()
‘此处修改数据
objadap.Update(objDSet.Tables("Info"))
objconn.Close()
MsgBox("保存成功", , "提示") '******
Catch ex As Exception
MsgBox(Err.Description, MsgBoxStyle.Critical, Err.Number)
End Try