Hi - a question for you all for my own knowledge and learning.
I have a form which sends and retrieves data to/from an Access database. The form comprises a couple of Check Boxes, among other things. I found that when saving/retrieving data from the DB, i received the following error:
'An unhandled exception of type 'System.ComponentModel.InvalidEnumArgumentException' occurred in System.Windows.Forms.dll
Additional information: The value of argument 'value' (-1) is invalid for Enum type 'CheckState'.'
The offending code:
Code:
Imports System.Data.OleDb
Private Sub btnRetrieveData_Click(sender As Object, e As EventArgs) Handles btnRetrieveData.Click
Dim con As New OleDb.OleDbConnection
Dim dbProvider$ = "Provider=MICROSOFT.ACE.OLEDB.12.0;"
Dim dbSource$ = "Data Source = C:\Desktop\Access.accdb"
Dim DS As New DataSet
Dim DA As New OleDb.OleDbDataAdapter
con.ConnectionString = dbProvider & dbSource
con.Open()
DA = New OleDbDataAdapter(Select * From tb, con)
DA.Fill(DS, "FirstTable")
ckPplFFTD.CheckState = DS.Tables("FirstTable").Rows(inc).Item(5)
ckPplSEND.CheckState = DS.Tables("FirstTable").Rows(inc).Item(7)
con.Close()
End Sub
Ok... so... after a bit of head scratching, i figured Access' Check Box integer values were different to VB.Net's Check Box values. So... i changed my code to the following and the form worked:
Code:
If DS.Tables("FirstTable").Rows(inc).Item(5) = -1 Then
ckPplFFTD.CheckState = DS.Tables("FirstTable").Rows(inc).Item(5) + 2
Else
ckPplFFTD.CheckState = DS.Tables("FirstTable").Rows(inc).Item(5)
End If
If DS.Tables("FirstTable").Rows(inc).Item(7) = -1 Then
ckPplSEND.CheckState = DS.Tables("FirstTable").Rows(inc).Item(7) + 2
Else
ckPplSEND.CheckState = DS.Tables("FirstTable").Rows(inc).Item(7)
End If
My question: Is this the correct way of doing things?? It seems a little clunky and i cant help but think i'm not doing things as they should be done.
Thanks in advance.
GTD