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