注册 登录
编程论坛 VB.NET论坛

数据为什么保存不了?请各位大侠帮我分析分析,指出解决方案。谢谢!

lhfwhrlzh 发布于 2018-02-04 23:58, 1807 次点击
调用下面的函数保存数据, 数据为什么保存不了?请各位大侠帮我分析分析,指出解决方案。谢谢!

      Private Function Save_Data() As Boolean '保存数据
        Dim AccessString As String = "select * FROM 个人信息"
        Dim AccessConn As New OleDb.OleDbConnection(AccessConnectionString)
        AccessConn.Open()
        Dim AccessAdapter As OleDbDataAdapter = New OleDbDataAdapter(AccessString, AccessConn)
        Dim AccessCmdBulid As New OleDb.OleDbCommandBuilder(AccessAdapter)

        Try
            AccessAdapter.Update(DataGridView1.DataSource)
            Return True
        Catch ex As Exception
            Console.WriteLine(ex.Message)
            MsgBox("数据保存失败!" & vbCrLf & ex.Message.ToString, MsgBoxStyle.Critical)
            Return False
        Finally
            AccessAdapter.Dispose()
            AccessCmdBulid.Dispose()
        End Try
    End Function
3 回复
#2
xyxcc1772018-02-05 17:14
Private Function Save_Data() As Boolean '保存数据
       Dim AccessCmdBulid As New OleDb.OleDbCommandBuilder(AccessAdapter)

        Try
            AccessAdapter.Update(DataGridView1.DataSource)
            Return True
        Catch ex As Exception
            Console.WriteLine(ex.Message)
            MsgBox("数据保存失败!" & vbCrLf & ex.Message.ToString, MsgBoxStyle.Critical)
            Return False
        Finally
            AccessAdapter.Dispose()
            AccessCmdBulid.Dispose()
        End Try
    End Function
#3
lhfwhrlzh2018-02-06 02:59
回复 2楼 xyxcc177
不能解决问题
#4
xyxcc1772018-02-06 11:42
datagridview的数据源必是dataset中的表
1