Solved

I need to update tables in SQL Server.

Posted on 1998-07-16
5
165 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now