Primary Key Prob with SQL table innerjoin with primary key


Exception Details: System.Data.MissingPrimaryKeyException: Table doesn't have a primary key.

I have used Stored Procedure in SQL with innerjoin. I think this Stored Procedure is problem because when I use one table with primary key rather using innerjoin to get data from 2 SQL tables I don't have this Table doesn't have a primary key:

CREATE proc dbo._BookLink
select Convert(nvarchar(10),BookID)as BookId, CategoryName,Title, Author, Publisher, PublicationDate, ISBN, Price, BriefDesc, FullDesc, [Image], link, htmlready
from dbo.BookCategory inner join dbo.Book
on Book.CategoryID = _BookCategory.CategoryID
Order by Book.Title
Book has Primary Key set to BookID
BookCategory has Primary Key set to CategoryID
My Function that calls this stored procdure:

Public Shared Function GetBook() As DataSet
Dim myCONN As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Dim myCMD As SqlCommand = New SqlCommand("BookLink", myCONN)

myCMD.CommandType = CommandType.StoredProcedure
myCMD.Connection = myCONN
Dim myDA As New SqlDataAdapter
myDA.MissingSchemaAction = MissingSchemaAction.AddWithKey
myDA.SelectCommand = myCMD
Dim myDS As New DataSet
myDA.Fill(myDS, "Book")
Return myDS

End Function
I used MissingSchemaAction.AddWithKey which I believe means that if the data table doesn't have a primary key it will add one for me.
Private Sub DisplayBook2(
sSelect = Request.QueryString("bookid")
dr = ds.Tables("Book").Rows.Find(sSelect)
End Sub
I used this similar code for 3 other pages and I don't get this primary key error. I only get it on this page and this is the only page I am using inner join. All other pages use only one SQL table with primary key.
It seems like when I use innerjoin, the primary key doesn't follow the column that is set with primary key.
What is wrong????

9/4/2004 3:52:28 AM 93655 articles. 6 followers. Follow

0 Replies

Similar Articles

[PageSpeed] 14


Similar Artilces:

SQL statement failed, no primary key value for foreign key ... in table ...
Problem: SQL statement failed, no primary key value for foreign key ... in table ... After deleting or changing primary key values in either consolidated or remote database. Question: Are there any triggers that can resolve inserting a record that has a foreign key value with no existing primary key value in primary table? Description: We have a serious problem with the dbremote program. I think it's a general problem that could appear in every database with related tables. Everytime the problem turns up we must create new remote databases from the consolidated datab...

Primary Key & Index on Primary Key Field
Adaptive Server Anywhere Network Server Version I found that a query was spiking my client's server's cpu and, after time seemed to be the culprit of a meltdown. After adding an index on the Primary Key, the issue seemed disappear. I'm wondering why and if I should be adding an index to all of my tables primary keys (I assumed this was done automatically by Sybase). Below is the query, then the Plan before and after the addition of the index. The major thing I see different is that there is no disk read after the index has been added. Select rss.Eve...

Foregin key and primary key relationship in form???
  Hi i have 2 table.. Table1UID         Username1               AB2               CD3               DD Table 2ITEM       Price          UIDPOO1      20.00          1POO2      10.00          2POO3       15.00         1 Now i am letting the Admin to delete the user in table1But since UID 1 and...

multiple fields as primary key and primary key error message
Hello, I have a two-fold question, one of which is very basic, but I am very interested in feedback as I am fairly new to dbase design. I have a UsageData table with the following fields: Facility, UsageDate, ProductID, BegInventory, PurchaseAmount, EndInventory.  The user can only insert one entry per Facility per month (UsageDate gets set to mm/1/yyyy programatically) per ProductID - therefore the combination of these three fields is what makes that record unique, and together they serve as the primary key.  I have seen and heard that using multiple fie...

how to set primary key in datatable and find the record based on primary key
Hi all, I want to set primary key to my datatable and find the index of my record in my datatable based on that primary key. Can any one please help me regarding this? Regards, Ramesh Rathi  first, create a PK like this (using SQL 2005) browse to database, table, the column and right click an int column (your pk to be)watch the column propertiesmark identity specification as YESIs identity YesIdentity increment 1Secondthe index is your pk if you declare it this. Unless you delete the row, so I recommend a logical delete..Good luck   TFPlease Mar...

Clustered Primary Key and Foreign Key: T-SQL
I am having a little trouble getting this to work right, but have come a ways since I started this.......other tables created first and with no problems..... then these two with the last table being the problemI need to set one foreign key in the second table referencing the first table.But, the primary key is clustered with the two foreign keys and I get the error....There are no primary or candidate keys in the referenced table 'courseScores' that match the referencing column list in the foreign key 'FK_course'.CREATE TABLE dbo.courseScores   (     course...

integer primary/foreign key vs. varchar(255) primary/foreign key
Hello. Is there any principal performance (or some other) difference between using the integer primary/foreign key and using the string (varchar(255)) keys in queries that use tables joins? Server is Sybase SQL Anywhere 5.5.04 Yes! The primary key will only be made up of 12 bytes. By using an integer you ensure that your entire column is in the key. -- Jim Egan [TeamPS] Dynamic Data Solutions, Inc. Houston, TX *********************************************************** Enterprise Applications in Your F...

Inserted records missing in sql table yet tables' primary key field has been incremented.
I have a sql sever 2005 express table with an automatically incremented primary key field. I use a Detailsview to insert new records and on the Detailsview itemInserted event, i send out automated notification emails. I then received two automated emails(indicating two records have been inserted) but looking at the database, the records are not there. Whats confusing me is that even the tables primary key field had been incremented by two, an indication that indeed the two records should actually be in table.  Recovering these records is not abig deal because i can re-enter them but ia...

Primary Keys containing common foreign keys from different tables
I have 2 tables Table 1 and Table 2 which have primary keys which include the same foreign key from a third Table 0. Table 1 has a primary key consisting of T1_KEY<pk> and T0_KEY<pk,fk>. Table 2 has a primary key consisting of T2_KEY<pk> and T0_KEY<pk,fk>. Now I want Table 3 to reference both Table 1 and Table 2 so that it has a primary key consisting of: T3_KEY<pk>, T0_KEY<pk, fk>, T1_KEY<pk, fk>, T2_KEY<pk, fk> I am trying to manually reverse engineer a database for which I only have a verbal description. I manage to achieve ...

Updating tables in sequence with primary key and foreign key relations
Hi all,        In my project i will have the  data in a collection of objects, I need to update series of tables with foreign key relations        Right now my code looks like this        foreach(object obj in Objects){        int accountId=Account.Insert(obj.accountOpenDate,obj.accountName);//this will update the accounts table and returns account id which is a Identity column in Acccounts table        int DebtId=Debt....

Difference between candidate key and primary key in sql server 2000.
hi can any explan  in detailed,the difference between the candidate key and primary key in sql server 2000 A table may have more than one combination of set of columns that could uniquely identify the rows in a table. Each combination is a Candidate key. We pick one of the Candidate keys to be the Primary key.Primary Key dont have NULL values, where as Candidate key column may contain one NULL value record.and By default Primary key is Clustered index.Somnath Mali.NET Developer , Pune INDIA.Please Mark As Answer If my reply helped you. Hi, read this thread : http://www...

SQL statement failed: (-194) No primary key value for foreign key
I'm getting this error message sporadically when my remote sites are replicating to my central server. The odd thing is the record that is the primary key value does exist! I'm at a lost...Does any have any idea, why this may be happening? Thanks Tasha Did the record exist at the time the error was reported? I have seen cases before where the Parent record is physically sent to the remote *after* the Child record. This would explain why the error was legitimately reported but when you look at the database later the Parent record now exists. -- -------------...

Primary Key/Foreign Key
Can I use SQL Commands to add Primary key or reference keys to existed tables? (Not a new table, that's why I can't use CREATE TABLE command.) If does, could someone give me some sample codes? Thanks. Hi John, What you need is the ALTER TABLE statement. Look for it in SQLA help for the syntax. Regards, Nat. John Chyan wrote in message <>... >Can I use SQL Commands to add Primary key or reference keys to existed >tables? (Not a new table, that's why I can't use CREATE TABLE command.) > >If does, could someone ...

AutoUpade UserId [Foreign Key] From the Primary Key UserId in the aspnet_Users table ?
 Hello everyoneI want the userId PrimaryKey in the aspnet_Users Table in the ASPNETDB.mdf  to Update it's foreign key in another table called ClientInfo in the same database, Once the User is created a new userId is created, i want this userId to be automatically entered in the foreign key table can that be accomplished?  You can have a trigger on aspnet_Users table doing the insert into the ClientInfo table.Regards,PrashantDont forget to click "Mark as Answer" on the post that helped you.  thanks for the fast would be great i...

Web resources about - Primary Key Prob with SQL table innerjoin with primary key -

MATLAB Documentation - MathWorks Deutschland
MATLAB is a high-level language and interactive environment for numerical computation, visualization, and programming.

Resources last updated: 12/6/2015 10:24:07 AM