Solved

I need to update tables in SQL Server.

Posted on 1998-07-16
5
167 Views
Last Modified: 2010-05-03
I need to update some tables in SQL Server from a VB application.
During the run time, these tables were not updatable for some reason.
I do not understand why they are not updatable.
This is the way I connect to SQL Server from a VB application as
the following:

    sConnect = "ODBC;DSN=ODBC_SQLServer;"
    sConnect = sConnect & "DATABASE=DatabaseName;"
    sConnect = sConnect & "UID=LoginID;" & "PWD="
    sConnect = sConnect & "Password;"
    Set WK = DBEngine.Workspaces(0)
    Set DB = WK.OpenDatabase("", False, False, sConnect)
    Set rs = DB.OpenRecordset("ChapterMemberRef", dbOpenDynaset, dbSeeChanges)

All tables in the SQL Server have permission to be updatable by
the login ID 'LoginID' and Password 'Password'.
The structure of 'ChapterMemberRef' has the following

MemberID       Integer
ChapterCode VarChar(5)

This table must allow to have duplicate MemberIDs and ChapterCodes.
There is no primary key in this table.
This table is a bridge table between a table named, Members which
has a primary key MemberID and another table named, Chapters which
has a primary key ChapterCode.

Does anybody have any suggestion?
Hope to hear your experienced answers from you soon. Thanks.

Hoosang
0
Comment
Question by:hoosang
  • 3
5 Comments
 

Author Comment

by:hoosang
ID: 1466036
Edited text of question
0
 
LVL 1

Expert Comment

by:brunchey
ID: 1466037
Could you send more code please.  Like all of it, with a comment on where you encountered the problem of not being able to update your code.
0
 

Author Comment

by:hoosang
ID: 1466038
After the code above, if I put a code as

rs.Add

Then VB application gave me an error

3027 This table is not updatable.
0
 
LVL 1

Accepted Solution

by:
DennisH earned 100 total points
ID: 1466039
The reason that the table is not updateable is because SQL Server requires a primary key in order to execute INSERT or SELECT statements through ODBC.  Add an AUTONUMBER field to this table and set the IDENTITY property of that field.  Save the Autonumber field value in your code and then use it for UPDATES.  You can ignore the autonumber field for INSERTS.
0
 

Author Comment

by:hoosang
ID: 1466040
I confirmed that your answer is correct. However, I like to know the reason behind it. I did not have any problem in MS Access.
Am I missing something in MS SQL Server? (Every time I create a table in MS SQL Server, do I need to set up at least one Primary Key in the table? Does this issue apply to other SQL servers (such as Oracle, Sybase, Informix and DB2)?)

Maybe I need to take SQL 101 class somewhere.


0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VBA Shell can't Find Word document 11 94
How to Add / Edit Windows Menu 4 61
MsgBox 4 61
Publisher:   Unknown     VB.exe Application 1 21
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question