Hello
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
As
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
GO
-------------------------------------------------------------------
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("C onnectionString"))
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????

