Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 9th, 2005, 10:04 PM
Authorized User
 
Join Date: Apr 2005
Location: Kuala Lumpur, Wilayah Persekutuan, Malaysia.
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default Pls help me!!

Hi, I get the following error when the same user log in n
borrow more than 1 book at one time.

My LoanRecord tbl in database is like this:
Borrow_Date dateTime 8 (Primary Key)
User_id char 10
Title_id char 10
Title varchar 150
Due_Date dateTime 8
Status char 1


Server Error in '/e-library' Application.
--------------------------------------------------------------------------------

Violation of PRIMARY KEY constraint 'PK_LoanRecord'. Cannot insert duplicate key in object 'LoanRecord'. The statement has been terminated.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Violation of PRIMARY KEY constraint 'PK_LoanRecord'. Cannot insert duplicate key in object 'LoanRecord'. The statement has been terminated.

Source Error:


Line 224: SqlDataAdapter1.InsertCommand.Parameters("@Status" ).Value = "N"
Line 225: 'SqlConnection1.Open()
Line 226: SqlDataAdapter1.InsertCommand.ExecuteNonQuery()
Line 227: SqlConnection1.Close()
Line 228: End Sub


Source File: c:\inetpub\wwwroot\e-library\Borrow.aspx.vb Line: 226

Stack Trace:


[SqlException: Violation of PRIMARY KEY constraint 'PK_LoanRecord'. Cannot insert duplicate key in object 'LoanRecord'.
The statement has been terminated.]
   System.Data.SqlClient.SqlCommand.ExecuteReader(Com mandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream)
   System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
   e_library.Borrow.Loan(String Title_id, String Title) in c:\inetpub\wwwroot\e-library\Borrow.aspx.vb:226
   e_library.Borrow.DataGrid1_ItemCommand(Object source, DataGridCommandEventArgs e) in c:\inetpub\wwwroot\e-library\Borrow.aspx.vb:147
   System.Web.UI.WebControls.DataGrid.OnItemCommand(D ataGridCommandEventArgs e)
   System.Web.UI.WebControls.DataGrid.OnBubbleEvent(O bject source, EventArgs e)
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
   System.Web.UI.WebControls.DataGridItem.OnBubbleEve nt(Object source, EventArgs e)
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
   System.Web.UI.WebControls.LinkButton.OnCommand(Com mandEventArgs e)
   System.Web.UI.WebControls.LinkButton.System.Web.UI .IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument)
   System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
   System.Web.UI.Page.ProcessRequestMain()




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.2032; ASP.NET Version:1.1.4322.2032

[code]

Thanks in advance for any help!

Irene

  #2 (permalink)  
Old June 9th, 2005, 10:09 PM
Authorized User
 
Join Date: Jul 2004
Location: , , .
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Read the error:

SqlException: Violation of PRIMARY KEY constraint 'PK_LoanRecord'. Cannot insert duplicate key in object 'LoanRecord'.

It clearly indicates that you are trying to insert a duplicate value in
a primary key column. Check your table structure.


  #3 (permalink)  
Old June 9th, 2005, 11:33 PM
Authorized User
 
Join Date: Apr 2005
Location: Kuala Lumpur, Wilayah Persekutuan, Malaysia.
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Now the Borrow_Date is primary key. When the user borrow more than
1 book at 1 time, the Borrow_Date will be same for the books he borrowed.

I guess the error is caused by that, am I right?

But the other columns may also have the duplicate values, do i need to create 1 more column such as Number n set it as Primary Key?

Thanks!


  #4 (permalink)  
Old June 10th, 2005, 01:10 AM
Authorized User
 
Join Date: Jul 2004
Location: , , .
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Correct. The error is caused due to Borrow_Date.
And yes, you need to create a new column, say, TransactionID,
and set it as Primary Key

  #5 (permalink)  
Old June 10th, 2005, 11:24 PM
Authorized User
 
Join Date: Apr 2005
Location: Kuala Lumpur, Wilayah Persekutuan, Malaysia.
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks, i'll try it out.

 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
pls help me.. nilusharief003 ASP.NET 2.0 Professional 5 December 4th, 2008 08:05 AM
I need help!!!!!!!!!!!!!!!!!!!!!!!!!!!! pls!!!!!!! ironchef Java Basics 2 September 26th, 2006 02:35 PM
Pls help me hoailing22 ASP.NET 1.0 and 1.1 Basics 3 May 24th, 2005 11:08 AM
Pls!!! I need your Help!!! Ariel ASP.NET 1.0 and 1.1 Basics 3 May 9th, 2005 06:34 PM



All times are GMT -4. The time now is 12:16 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.