I have just created my 2nd VB.Net application today where I have created the database in MS Access 2019 and created the project in VS. The project consists of 2 forms at present. A data entry form and a database editor which I have setup using a datagridview. The datagrid is working fine (so far) and loading the data I have created..
My problem is with the data entry form. I am assuming because I created the connection in the datagrid form this has all the details configured I need to access the database in the data entry form. With the first application I wrote I did not use the datagrid so defined all the connection details within the main application.. if I do this now I get the database is in use & cannot be opened which I suspect is because of the datagrid..
.. the cmd1.Connection=DBconnection is where I am struggling.. where can I find the variable for DBConnection as I am assuming I can reuse the details from the datagrid connectivity?
My problem is with the data entry form. I am assuming because I created the connection in the datagrid form this has all the details configured I need to access the database in the data entry form. With the first application I wrote I did not use the datagrid so defined all the connection details within the main application.. if I do this now I get the database is in use & cannot be opened which I suspect is because of the datagrid..
.. the cmd1.Connection=DBconnection is where I am struggling.. where can I find the variable for DBConnection as I am assuming I can reuse the details from the datagrid connectivity?
SQL Query:
Private Sub SQL_Read_Defaults()
'Raad default values for logging
Dim cmd1 As New OleDb.OleDbCommand
Try
sqlSelect1 = "SELECT RSTTX, RSTRX, Mode, Band FROM Defaults"
cmd1.Connection = DBconnection
cmd1.CommandText = sqlSelect1
Dim NAQdbReader As OleDbDataReader = cmd1.ExecuteReader()
If (NAQdbReader.HasRows) Then
'Retrieve data from SQL query
While NAQdbReader.Read
txtRSTTX.Text = NAQdbReader(0).ToString
txtRSTRX.Text = NAQdbReader(1).ToString
comMode.Text = NAQdbReader(2).ToString
comBand.Text = NAQdbReader(3).ToString
End While
Else
MsgBox("Defaults Tables empty!")
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub