Solved

I need to update tables in SQL Server.

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

911 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

23 Experts available now in Live!

Get 1:1 Help Now