I'm using VB to open an OleDbConnection and pull some data out of an Access database. Everything seems to work fine, except VB is reporting my table has no primary key.
Having no primary key means I can't search, find, update, or many other fun things you can generally do with a relational database.
I've been searching for a solution from the VB side with very little luck; perhaps the problem is on the Access side.
Here's some details about the table fields:
EntryKey - Long Integer, Autonumber, Indexed (No Duplicates)
It has the "Primary Key" icon next to it.
PersonKey and WeekKey - Long Integer, Number, Indexed (Duplicates OK)
When looking at Indexes, EntryKey has the "Primary Key" icon, Primary=Yes, Unique=Yes, Ignore Nulls=No.
PersonKey and WeekKey are neither Primary nor Unique (in this table).
So as best as I can tell, the table has a primary key.
On the VB side, the code looks like this:
Function fnOLEPullEntry(ByVal oleDBCon As OleDb.OleDbConnection, ByRef oleDBdata As OleDb.OleDbDataAdapter) As Boolean
Dim strSQL As String = "SELECT * FROM tblEntry WHERE PersonKey = " & Str(DisplayedPersonKey) & " AND WeekKey = " & Str(DisplayedWeekKey)
Dim TableCol(0) As DataColumn
oleDBdata = New OleDb.OleDbDataAdapter(strSQL, oleDBCon)
If rsD.Tables.Contains("Entry") Then rsD.Tables.Remove("Entry")
fnOLEPullEntry = True
Catch ex As Exception
fnOLEPullEntry = False
shouldn't your query criteria arguments have delimiters if they are strings/text fields
The fields are numbers, but the variable in code is a string. So, to keep the .NET police happy, I convert the numbers to string when concatenating the SQL string and the data adapter parameter is looking for a string.
The code runs fine and I get the data. But, when i try to use a Find function or try to update the data, VB reports "No Primary Key".