Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.1
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 3rd, 2004, 10:51 PM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 245
Thanks: 0
Thanked 0 Times in 0 Posts
Default Primary Key Prob with SQL SP with Primary Key

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????





Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL to identify the primary key in a table? dbayona SQL Server 2005 1 October 24th, 2007 02:33 AM
Foreign key not updating with Primary key xavier1945 BOOK: Access 2003 VBA Programmer's Reference 2 July 4th, 2007 09:48 PM
SQL Server Primary Key Incrementer tclancy SQL Server 2000 13 March 23rd, 2006 09:44 AM
SQL Server Primary key Lofa SQL Server 2000 12 September 29th, 2005 08:45 PM
FOREIGN KEY and PRIMARY KEY Constraints junemo Oracle 10 June 15th, 2004 01:00 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.