Results 1 to 3 of 3

Thread: Primary Key

  1. #1
    Join Date
    Apr 2004
    Location
    outside the rim
    Posts
    1,011

    Unanswered: Primary Key

    Howdy,

    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:
    Code:
        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
    
            Try
                oleDBdata = New OleDb.OleDbDataAdapter(strSQL, oleDBCon)
                If rsD.Tables.Contains("Entry") Then rsD.Tables.Remove("Entry")
                oleDBdata.Fill(rsD, "Entry")
                fnOLEPullEntry = True
            Catch ex As Exception
                fnOLEPullEntry = False
            End Try
        End Function

    VB 2008 Express
    Access 2003 running in 2000 mode

    Any thoughts?
    have fun!

    Todd S.
    click to email


    Independent Development Consultant
    Biz db & reports - SQL, Access, Crystal, Seradex and more
    Small, custom, unique programs - Office, VBA, .NET


    _________________________________________________
    Favorite message from Windows:
    There was an error displaying the previous error message

    Sadly, there was no error number to look up ...

  2. #2
    Join Date
    Apr 2004
    Location
    Derbyshire, UK
    Posts
    789
    Provided Answers: 1
    Hi

    My experiance of .Net is VERY limited, so my only comment is, shouldn't your query citeria arguments have delimiters if they are strings/text fields !

    "SELECT * FROM tblEntry WHERE PersonKey = '" & Str(DisplayedPersonKey) & "' AND WeekKey = '" & Str(DisplayedWeekKey) & "'"


    ??

    MTB

  3. #3
    Join Date
    Apr 2004
    Location
    outside the rim
    Posts
    1,011
    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".

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •