Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 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 November 9th, 2010, 06:50 AM
Registered User
 
Join Date: Nov 2010
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ok i get it although i remember setting the inserted event in the event tab. I changed it yet i still get an error in the markup view

Code:
Error	1	No overload for 'LinqDataSource1_Inserted' matches delegate 'System.EventHandler<System.Web.UI.WebControls.LinqDataSourceStatusEventArgs>'	C:\BegASPNET\Site1\ManagePhotoAlbum.aspx	57
please bear with me as i am still getting used to writing code
 
Old November 9th, 2010, 06:56 AM
Registered User
 
Join Date: Nov 2010
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

imar

i just double clicked to inserted event to bring up the method and this is what it writes

Code:
protected void  LinqDataSource1_Inserted(object sender, LinqDataSourceStatusEventArgs e)
{

}
isnt this odd...shouldnt it automatically generate the argument LinqDataSourceInsertEventArgs isntead of what is above?
 
Old November 9th, 2010, 06:57 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Yes, it should. But maybe you already wired up the wrong handler in the markup? Can you post the code for the entire page? E.g. the markup and its Code Behind?

imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old November 9th, 2010, 07:00 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Oh, my bad. Just checked my code again in VWD, and for Inserted, you get a Status args, and for Inserting you get an Insert args.

If you look at the source that comes with the book you'll see that NewObject is only used in Inserting event handlers....

Cheers, and sorry for the confusion.

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old November 9th, 2010, 09:20 PM
Registered User
 
Join Date: Nov 2010
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi imar

i managed to compile and request the NewPhotoAlbum.aspx page in my browser and filled in the name and clicked insert which took me to the managephotoalbum.aspx as step 16 instructs us to do. When i filled in all the required fileds and pressed insert i got an error as follows

Code:
The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Picture_Photoalbum". The conflict occurred in database "C:\BEGASPNET\SITE1\APP_DATA\PLANETWROX.MDF", table "dbo.Photoalbum", column 'Id'.
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: The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Picture_Photoalbum". The conflict occurred in database "C:\BEGASPNET\SITE1\APP_DATA\PLANETWROX.MDF", table "dbo.Photoalbum", column 'Id'.
The statement has been terminated.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[SqlException (0x80131904): The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Picture_Photoalbum". The conflict occurred in database "C:\BEGASPNET\SITE1\APP_DATA\PLANETWROX.MDF", table "dbo.Photoalbum", column 'Id'.
The statement has been terminated.]
   System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +1950890
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +4846875
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +194
   System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2392
   System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +33
   System.Data.SqlClient.SqlDataReader.get_MetaData() +83
   System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +297
   System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +954
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +162
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +32
   System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +141
   System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +12
   System.Data.Common.DbCommand.ExecuteReader() +12
   System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query, QueryInfo queryInfo, IObjectReaderFactory factory, Object[] parentArgs, Object[] userArgs, ICompiledSubQuery[] subQueries, Object lastResult) +975
   System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query, QueryInfo[] queryInfos, IObjectReaderFactory factory, Object[] userArguments, ICompiledSubQuery[] subQueries) +113
   System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query) +344
   System.Data.Linq.StandardChangeDirector.DynamicInsert(TrackedObject item) +136
   System.Data.Linq.StandardChangeDirector.Insert(TrackedObject item) +202
   System.Data.Linq.ChangeProcessor.SubmitChanges(ConflictMode failureMode) +260
   System.Data.Linq.DataContext.SubmitChanges(ConflictMode failureMode) +331
   System.Data.Linq.DataContext.SubmitChanges() +19
   System.Web.UI.WebControls.LinqToSqlWrapper.SubmitChanges(DataContext dataContext) +9
   System.Web.UI.WebControls.LinqDataSourceView.InsertDataObject(Object dataContext, Object table, Object newDataObject) +83
   System.Web.UI.WebControls.LinqDataSourceView.ExecuteInsert(IDictionary values) +448
   System.Web.UI.DataSourceView.Insert(IDictionary values, DataSourceViewOperationCallback callback) +86
   System.Web.UI.WebControls.ListView.HandleInsert(ListViewItem item, Boolean causesValidation) +277
   System.Web.UI.WebControls.ListView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +652
   System.Web.UI.WebControls.ListView.OnBubbleEvent(Object source, EventArgs e) +233
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
   System.Web.UI.WebControls.ListViewItem.OnBubbleEvent(Object source, EventArgs e) +112
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
   System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +118
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +166
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
i remember creating both the picture and photoalbum table sand setting both primary keys in these two tables as the Id. I cannot figure out why the sql insert statement was terminated and what is bringing up this conflict when i try to insert the name url and tooltip fields.
 
Old November 10th, 2010, 02:50 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
I cannot figure out why the sql insert statement was terminated
Neither can I without seeing the code.... ;-) Can you post it?

Also, are you following the book exactly? If so, did you compare your source files with those that come with the book?

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old November 24th, 2010, 12:38 AM
Registered User
 
Join Date: Nov 2010
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

imar
i have compared my code with your source files.The files that i am comparing are ManagePhotoAlbum and NewPhotoAlbum and i do not see any difference. I am on chapter 13 so i do not have all the following chapters in my code

Here is my code for both cs files mentioned above and the resulting error i get when i get redirected to the ManagePhotalbum page from the newphotalbum page

ManagePhotoAlbum
Code:
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Template1 : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void LinqDataSource1_Inserting(object sender, LinqDataSourceInsertEventArgs e)
    {

        Picture myPicture = (Picture)e.NewObject;
        myPicture.PhotoalbumId = Convert.ToInt32(Request.QueryString.Get("PhotoAlbumId"));
    }
}

NewPhotoAlbum

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Template1 : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void LinqDataSource1_Inserted(object sender, LinqDataSourceStatusEventArgs e)
    {
        Photoalbum myPhotoalbum = (Photoalbum)e.Result;
        Response.Redirect(string.Format("ManagePhotoAlbum.aspx?PhotoAlbumId={0}", myPhotoalbum.Id.ToString()));
    }
}
error recieved is

The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Picture_Photoalbum". The conflict occurred in database "C:\BEGASPNET\SITE1\APP_DATA\PLANETWROX.MDF", table "dbo.Photoalbum", column 'Id'.
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: The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Picture_Photoalbum". The conflict occurred in database "C:\BEGASPNET\SITE1\APP_DATA\PLANETWROX.MDF", table "dbo.Photoalbum", column 'Id'.
The statement has been terminated.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[SqlException (0x80131904): The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Picture_Photoalbum". The conflict occurred in database "C:\BEGASPNET\SITE1\APP_DATA\PLANETWROX.MDF", table "dbo.Photoalbum", column 'Id'.
The statement has been terminated.]
System.Data.SqlClient.SqlConnection.OnError(SqlExc eption exception, Boolean breakConnection) +1950890
System.Data.SqlClient.SqlInternalConnection.OnErro r(SqlException exception, Boolean breakConnection) +4846875
System.Data.SqlClient.TdsParser.ThrowExceptionAndW arning(TdsParserStateObject stateObj) +194
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2392
System.Data.SqlClient.SqlDataReader.ConsumeMetaDat a() +33
System.Data.SqlClient.SqlDataReader.get_MetaData() +83
System.Data.SqlClient.SqlCommand.FinishExecuteRead er(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +297
System.Data.SqlClient.SqlCommand.RunExecuteReaderT ds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +954
System.Data.SqlClient.SqlCommand.RunExecuteReader( CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +162
System.Data.SqlClient.SqlCommand.RunExecuteReader( CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +32
System.Data.SqlClient.SqlCommand.ExecuteReader(Com mandBehavior behavior, String method) +141
System.Data.SqlClient.SqlCommand.ExecuteDbDataRead er(CommandBehavior behavior) +12
System.Data.Common.DbCommand.ExecuteReader() +12
System.Data.Linq.SqlClient.SqlProvider.Execute(Exp ression query, QueryInfo queryInfo, IObjectReaderFactory factory, Object[] parentArgs, Object[] userArgs, ICompiledSubQuery[] subQueries, Object lastResult) +975
System.Data.Linq.SqlClient.SqlProvider.ExecuteAll( Expression query, QueryInfo[] queryInfos, IObjectReaderFactory factory, Object[] userArguments, ICompiledSubQuery[] subQueries) +113
System.Data.Linq.SqlClient.SqlProvider.System.Data .Linq.Provider.IProvider.Execute(Expression query) +344
System.Data.Linq.StandardChangeDirector.DynamicIns ert(TrackedObject item) +136
System.Data.Linq.StandardChangeDirector.Insert(Tra ckedObject item) +202
System.Data.Linq.ChangeProcessor.SubmitChanges(Con flictMode failureMode) +260
System.Data.Linq.DataContext.SubmitChanges(Conflic tMode failureMode) +331
System.Data.Linq.DataContext.SubmitChanges() +19
System.Web.UI.WebControls.LinqToSqlWrapper.SubmitC hanges(DataContext dataContext) +9
System.Web.UI.WebControls.LinqDataSourceView.Inser tDataObject(Object dataContext, Object table, Object newDataObject) +83
System.Web.UI.WebControls.LinqDataSourceView.Execu teInsert(IDictionary values) +448
System.Web.UI.DataSourceView.Insert(IDictionary values, DataSourceViewOperationCallback callback) +86
System.Web.UI.WebControls.ListView.HandleInsert(Li stViewItem item, Boolean causesValidation) +277
System.Web.UI.WebControls.ListView.HandleEvent(Eve ntArgs e, Boolean causesValidation, String validationGroup) +652
System.Web.UI.WebControls.ListView.OnBubbleEvent(O bject source, EventArgs e) +233
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
System.Web.UI.WebControls.ListViewItem.OnBubbleEve nt(Object source, EventArgs e) +112
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
System.Web.UI.WebControls.Button.OnCommand(Command EventArgs e) +118
System.Web.UI.WebControls.Button.RaisePostBackEven t(String eventArgument) +166
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

If you find some time your assistance would be greatly appreciated
 
Old November 24th, 2010, 03:36 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Are you sure you created the correct relationship in the database between PhotoAlbum.Id and Picture.PhotoAlbumId? Maybe you accidentally linked both ID columns instead?

You could see if your code works with my database, or vice versa. That makes it easier to track down the oproblem.

Also, I noticed all your pages are called "public partial class Template1". This seems like an incorrect implementation of your custom Base Page template to me. While it may work for now, it may get you into troubles later.

Finally, can you verify that PhotoAlbumId in the querystring on the request for ManagePhotoAlbum.aspx does indeed contain the ID of a PhotoAlbum in your database when you create a new album and then add pictures?

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 5 page 156 Example Step 4 NoraBelle BOOK: Professional Microsoft SQL Server 2008 Integration Services ISBN: 978-0-470-24795-2 1 August 2nd, 2010 03:29 PM
SQL Error, p. 456, step 16 member4953 BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 2 April 8th, 2009 01:19 PM
Chapter 16 Try It Out Page 498 Step 7 workib BOOK: Beginning Microsoft Visual C# 2008 ISBN: 978-0-470-19135-4 1 October 9th, 2008 08:22 PM
Page 222 Step 5 Whitney Schopf BOOK: Beginning Visual Basic 2005 ISBN: 978-0-7645-7401-6 1 November 6th, 2006 06:43 AM
step of opening a web page somnath.kartic VS.NET 2002/2003 0 March 30th, 2006 03:24 AM





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