[RESOLVED]数据集未更新.如何? [英] [RESOLVED]DataSet not updating. How to?

查看:60
本文介绍了[RESOLVED]数据集未更新.如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我刚刚开始为简单的Visual Basic游戏开发应用程序.
我希望人们能够使用在应用程序内创建并存储在.mdf 文件中的帐户登录.

I just started developing an app for a simple Visual Basic game.
I want people to be able to log in using an account created in-app and stored on a .mdf file.

该文件已经创建并链接到我的应用程序,但事情是这样的:
每当我启动程序时,我都会看到一个空的DataGrid'cos,我还没有添加任何记录.

The file's already created and linked to my application, but here's the thing:
Whenever I start the program I can see the empty DataGrid 'cos I haven't added any records yet.

我做了一个名为添加新"的按钮,会向数据集添加一条记录,为其提供一个自动ID,并设置一个帐户名和密码(account1和pass1).

I made a button called "Add New" which adds a record to the DataSet, giving it an automated Id, and a set account name and password (account1 and pass1).

保存"按钮应将这些更改保存到DataSet中,事实是:当我关闭应用程序并再次打开它时,更改已消失.

The save button should save these changes to the DataSet, the thing is: When I close the app and open it again the changes are gone.

我的源代码:

Public Class AccountInput
    Private Sub AccountInput_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'TODO: esta línea de código carga datos en la tabla 'AlphaDBDataSet.Accounts' Puede moverla o quitarla según sea necesario.
        Me.AccountsTableAdapter.Fill(Me.AlphaDBDataSet.Accounts)

    End Sub

    Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
        Try
            Me.Validate()
            Me.AccountsBindingSource.EndEdit()
            Me.AccountsTableAdapter.Update(Me.AlphaDBDataSet.Accounts)
            MsgBox("Update successful")
        Catch ex As Exception
            MsgBox("Update failed.")
        End Try

    End Sub

    Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles btnDelete.Click
        AccountsBindingSource.RemoveCurrent()
        AccountsTableAdapter.Update(AlphaDBDataSet)
        MsgBox("Entry deleted.")
    End Sub

    Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
        Dim newAccountRow As AlphaDBDataSet.AccountsRow
        newAccountRow = Me.AlphaDBDataSet.Accounts.NewAccountsRow()
        newAccountRow.Id = 0
        newAccountRow.AccountName = "Account1"
        newAccountRow.Password = "pass1"
        ' Add the row to the account table
        Me.AlphaDBDataSet.Accounts.Rows.Add(newAccountRow)
        ' Save the new row to the database
        Me.TableAdapterManager.UpdateAll(Me.AlphaDBDataSet)

    End Sub
End Class

在验证我的帐户之前无法上传图像.

Cannot upload images until my account is verified.

我真的很感谢任何人的帮助.抱歉,将其设置得太长.

I'd really appreciate anyone's help. Sorry for making this too long.

推荐答案

当我关闭应用程序并再次打开它时,更改已消失.

When I close the app and open it again the changes are gone.

可能是此处讨论的问题:
https://visualstudiomagazine.com/blogs/tool-tracker/2012/05/dealing-with-local-databases-or-why-your-updates-dont-stick.aspx

Could be the issue discussed here:
https://visualstudiomagazine.com/blogs/tool-tracker/2012/05/dealing-with-local-databases-or-why-your-updates-dont-stick.aspx


这篇关于[RESOLVED]数据集未更新.如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆