使用vb 2010添加到MS Access数据库的记录未保存 [英] Records added to ms access database with vb 2010 not saving

查看:87
本文介绍了使用vb 2010添加到MS Access数据库的记录未保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个简单的数据记录程序,但是我几乎没有数据库经验.我写了一个VB表单应用程序来将数据记录到ms访问,然后对数据进行图形绘制,但是在将记录添加到数据库时遇到了麻烦.

I'm working on a simple data logging program, and I have little to no database experience. I wrote a little VB forms app to log the data to ms access and then graph the data, but I'm having trouble with adding records to the database.

首先,我在Access中创建了一个简单的单表数据库.然后,我将数据库作为数据源添加到项目中,并使用向导为其提供了数据集.现在,我的代码如下:

First, I created a simple one table database in access. Then, I added the database to the project as a data source, and gave it a data set using the wizard. Right now my code looks like this:

Public Class mainForm

Dim da As New dsTableAdapters.Sensor_DataTableAdapter

...

我的数据库由简单称为Sensor_Data的表组成.我的数据集就是Ds,它是在我将数据库添加为数据源时创建的.每当有新数据到达时,我就调用updAccess()子例程.请忽略开关盒.这是为了将来的功能.

My database consists of table simply called Sensor_Data. My data set is simply Ds which was created when I added the database as a data source. I call the updAccess() subroutine whenever new data arrives. Please ignore the switch case. It is for future functionality.

...

Private Sub updAccess(ByVal data() As String)
    Select Case data(0)
        Case "001"
            Ds.Sensor_Data.Clear()
            da.Fill(Ds.Sensor_Data)

            Dim dsNewRow As DataRow = Ds.Sensor_Data.NewSensor_DataRow

            dsNewRow.Item("Sensor 1") = data(1)
            dsNewRow.Item("Sensor 2") = data(2)
            dsNewRow.Item("Sensor 3") = data(3)
            dsNewRow.Item("Sensor 4") = data(4)
            dsNewRow.Item("Sensor 5") = data(5)
            dsNewRow.Item("Sensor 6") = data(6)
            dsNewRow.Item("Sensor 7") = data(7)
            dsNewRow.Item("Sensor 8") = data(8)
            dsNewRow.Item("Sensor 9") = data(9)
            dsNewRow.Item("Sensor 10") = data(10)

            Ds.Sensor_Data.AddSensor_DataRow(dsNewRow)
            da.Update(Ds.Sensor_Data)

        Case "002"
            'TODO: update settings panel
    End Select
End Sub

...

在构建或运行时没有问题,但是在程序运行后我看不到对数据库的更改.任何输入,不胜感激.另外,也欢迎任何推荐的参考材料.

There are no problems during build or run time, but I do not see changes to database after the program runs. Any input is greatly appreciated. Also, any recommended reference material is also welcomed.

推荐答案

因此,在拔掉头发几周后.数据库正在被良好地更新,但是我没有在bin \ debug文件夹中查看数据库的副本.那好吧.现在我知道了.

So after several weeks of pulling out my hair. The database was being updated fine, but I wasn't looking at the copy of the database in the bin\debug folder. Oh well. Now I know.

这篇关于使用vb 2010添加到MS Access数据库的记录未保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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