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

September 23rd, 2009, 11:10 PM
|
|
Friend of Wrox
|
|
Join Date: Sep 2009
Posts: 165
Thanks: 5
Thanked 6 Times in 6 Posts
|
|
Chapter 12: last try it out, Data is not being updated in the database
Hello everyone,
I have gone through the chapter 12, but until last exercise it worked smoothly. Now in the last exercise (Page no. 413) when I try to enter the data in fields that works but when I click to "Insert" then page performs postback but data is not stored in database and hence not reflected in the "Review.aspx" page at all.
Even page runs smoothly in browser and no any kind of error is provided while opening the page in browser. I have gone through step by step , so no chance of error regarding connectivity.
Any help would be highly appreciated.
|
|

September 24th, 2009, 01:19 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
I am sure you can imagine what my first response is going to be, as it'll be the same as many other posts:
Please, please provide code. Post your Markup and Code Behind and any other information that might be relevant.
Cheers,
Imar
Last edited by Imar; November 25th, 2009 at 11:28 AM..
|
|

November 25th, 2009, 10:18 AM
|
|
Registered User
|
|
Join Date: Nov 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Same Problem - Unable to Insert
Great book! Until now I've had no problems. Like the previous poster, I am unable to Insert. Updating works fine. I tried matching my AddEditReview with your source and found no discrepancies. Here is my code:
AddEditReview.aspx:
Code:
<%@ Page Title="Planet Wrox - Management-Insert and Update Reviews" Language="C#" MasterPageFile="~/MasterPages/ManagementMaster.master" AutoEventWireup="true" CodeFile="AddEditReview.aspx.cs" Inherits="Management_AddEditReview" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" Runat="Server">
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
DataKeyNames="Id" DataSourceID="SqlDataSource1" DefaultMode="Insert"
Height="50px" Width="125px" oniteminserted="DetailsView1_ItemInserted"
oniteminserting="DetailsView1_ItemInserting"
onitemupdated="DetailsView1_ItemUpdated"
onitemupdating="DetailsView1_ItemUpdating">
<Fields>
<asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False"
ReadOnly="True" SortExpression="Id" />
<asp:TemplateField HeaderText="Title" SortExpression="Title">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Title") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Title") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="reqVal1" ControlToValidate="TextBox1" runat="server" ErrorMessage="Please enter a title"></asp:RequiredFieldValidator>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Title") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="reqVal2" ControlToValidate="TextBox1" runat="server" ErrorMessage="Please enter a title"></asp:RequiredFieldValidator>
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Summary" SortExpression="Summary">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("Summary") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox2" TextMode="MultiLine" Width="500" Height="100" runat="server" Text='<%# Bind("Summary") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="reqVal3" ControlToValidate="TextBox2" runat="server" ErrorMessage="Please enter a summary"></asp:RequiredFieldValidator>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox2" TextMode="MultiLine" Width="500" Height="100" runat="server" Text='<%# Bind("Summary") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="reqVal4" ControlToValidate="TextBox2" runat="server" ErrorMessage="Please enter a summary"></asp:RequiredFieldValidator>
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Body" SortExpression="Body">
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("Body") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox3" TextMode="MultiLine" Width="500" Height="100" runat="server" Text='<%# Bind("Body") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox3" TextMode="MultiLine" Width="500" Height="100" runat="server" Text='<%# Bind("Body") %>'></asp:TextBox>
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="GenreId" SortExpression="GenreId">
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("GenreId") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="sdsGenres"
DataTextField="Name" DataValueField="Id" SelectedValue='<%# Bind("GenreId") %>'>
</asp:DropDownList>
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="sdsGenres"
DataTextField="Name" DataValueField="Id" SelectedValue='<%# Bind("GenreId") %>'>
</asp:DropDownList>
</InsertItemTemplate>
</asp:TemplateField>
<asp:CheckBoxField DataField="Authorized" HeaderText="Authorized"
SortExpression="Authorized" />
<asp:BoundField DataField="UpdateDateTime" HeaderText="UpdateDateTime"
SortExpression="UpdateDateTime" Visible="False" />
<asp:CommandField ShowEditButton="True" ShowInsertButton="True" />
</Fields>
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:PlanetWroxConnectionString1 %>"
DeleteCommand="DELETE FROM [Review] WHERE [Id] = @Id"
InsertCommand="INSERT INTO [Review] ([Title], [Summary], [Body], [GenreId], [Authorized], [UpdateDateTime]) VALUES (@Title, @Summary, @Body, @GenreId, @Authorized, @UpdateDateTime)"
SelectCommand="SELECT [Id], [Title], [Summary], [Body], [GenreId], [Authorized], [UpdateDateTime] FROM [Review] WHERE ([Id] = @Id)"
UpdateCommand="UPDATE [Review] SET [Title] = @Title, [Summary] = @Summary, [Body] = @Body, [GenreId] = @GenreId, [Authorized] = @Authorized, [UpdateDateTime] = @UpdateDateTime WHERE [Id] = @Id">
<SelectParameters>
<asp:QueryStringParameter Name="Id" QueryStringField="Id" Type="Int32" />
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name="Id" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="Title" Type="String" />
<asp:Parameter Name="Summary" Type="String" />
<asp:Parameter Name="Body" Type="String" />
<asp:Parameter Name="GenreId" Type="Int32" />
<asp:Parameter Name="Authorized" Type="Boolean" />
<asp:Parameter Name="UpdateDateTime" Type="DateTime" />
<asp:Parameter Name="Id" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="Title" Type="String" />
<asp:Parameter Name="Summary" Type="String" />
<asp:Parameter Name="Body" Type="String" />
<asp:Parameter Name="GenreId" Type="Int32" />
<asp:Parameter Name="Authorized" Type="Boolean" />
<asp:Parameter Name="UpdateDateTime" Type="DateTime" />
</InsertParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="sdsGenres" runat="server"
ConnectionString="<%$ ConnectionStrings:PlanetWroxConnectionString1 %>"
SelectCommand="SELECT [Id], [Name] FROM [Genre] ORDER BY [SortOrder]">
</asp:SqlDataSource>
</asp:Content>
AddEditReview.aspx.cs
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 Management_AddEditReview : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString.Get("Id") != null)
{
DetailsView1.DefaultMode = DetailsViewMode.Edit;
}
}
protected void DetailsView1_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
{
EndEditing();
}
protected void DetailsView1_ItemInserting(object sender, DetailsViewInsertEventArgs e)
{
e.Values["UpdateDateTime"] = DateTime.Now;
}
protected void DetailsView1_ItemUpdated(object sender, DetailsViewUpdatedEventArgs e)
{
EndEditing();
}
protected void DetailsView1_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
{
e.NewValues["UpdateDateTime"] = DateTime.Now;
}
private void EndEditing()
{
Response.Redirect("Reviews.aspx");
}
}
Again, great book. I wanted to jump right in to the ASP.NET MVC 1.0 Wrox book right away, but figured I would start with your book first. No problems I couldn't figure out until now. Any guidance would be appreciated.
Thanks,
Nick
|
|

November 25th, 2009, 11:27 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi Nick,
Is it possible that the relationships in the database and thus in the LINQ diagram are not OK?
What do you see when you open the properties for the relationship between Genre and Review in the *SQL Server* diagram designer? Which columns are related there?
As you said, the code looks fine; pretty much identical to that of the book so it must be something else.
When you insert a review, do you get an error?
Imar
|
|

November 30th, 2009, 03:53 PM
|
|
Registered User
|
|
Join Date: Nov 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Relationships
Thanks for the reply Imar,
I'm using the express version if that matters. In the Reviews and Genres Relationship, the columns are as follows:
Primary key table: Genre
Primary key column: Id
Foreign key table: Review
Foreign key column: GenreId
Nick
|
|

November 30th, 2009, 03:59 PM
|
|
Registered User
|
|
Join Date: Nov 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Fixed now
Disregard my post.
For some reason it's working now. I'm chalking it up to test environment hiccup. I've had occasions where I would save and run only to find it had not saved. Even the Express version might be a bit much for my single core laptop.
Thanks for your quick assistance anyway.
Nick
|
|

November 30th, 2009, 03:59 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Can you send me a zipped copy of your site? If you send me a message from my site ( http://imar.spaanjaars.com/) I'll reply so you know my e-mail address. Then if you send the site I'll take a look....
Cheers,
Imar
|
|

November 30th, 2009, 04:01 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
I think our posts just crossed each other.... ;-)
Glad it'sd working now....
Cheers,
Imar
|
|
 |