Solved

I need to update tables in SQL Server.

Posted on 1998-07-16
5
169 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

726 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