Records added to ms access database with vb 2010 n

2019-09-09 02:14发布

问题:

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.

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

...

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.

回答1:

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.