Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Beginning ASP.NET 4 : in C# and VB
|
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB 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 January 22nd, 2015, 06:28 AM
Registered User
 
Join Date: Jan 2015
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Smile Chapter 13: Displaying & Updating Data - With stored proecdures?

Hello,
I'm new to asp.net. I'm learning from "Beginning ASP.Net 4: in C# & VB". I've tried the examples in the chapter successfully ("Using the GridView and SqlDataSource Controls" & "Inserting Data with the DetailsView Control"). I've also managed to adapt it to my own project.

"Using the GridView and SqlDataSource Controls"
It work okay when i replace w/ stored procedures.

"Inserting Data with the DetailsView Control"
It does not work w/ stored procedures.

Pls. advise.

Pls. see code, below.

ASPLDLMarketDetail.aspx
Code:
<%@ Page Title="ASPL DL: Create/Edit New Market" Language="VB" MasterPageFile="~/MasterPages/Management.master" AutoEventWireup="false" CodeFile="ASPLDLMarketDetail.aspx.vb" Inherits="Management_ASPLDLMarketDetail" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <asp:Label ID="lblMarket" runat="server" Text="Create/Edit Market"></asp:Label>
    <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" 
        DataKeyNames="ID" DataSourceID="sdsWebGetMarketByID" Height="50px" 
        Width="125px" DefaultMode="Insert">
        <Fields>
            <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" 
                ReadOnly="True" SortExpression="ID" />
            <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
            <asp:BoundField DataField="Description" HeaderText="Description" 
                SortExpression="Description" />
            <asp:TemplateField HeaderText="CategoryID" SortExpression="CategoryID">
                <EditItemTemplate>
                    <asp:DropDownList ID="DropDownList1" runat="server" 
                        DataSourceID="sdsWebGetCategory" DataTextField="Name" DataValueField="ID" 
                        SelectedValue='<%# Bind("CategoryID") %>' AutoPostBack="True">
                    </asp:DropDownList>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <asp:DropDownList ID="DropDownList1" runat="server" 
                        DataSourceID="sdsWebGetCategory" DataTextField="Name" DataValueField="ID" 
                        SelectedValue='<%# Bind("CategoryID") %>' AutoPostBack="True">
                    </asp:DropDownList>
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("CategoryID") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="EnterOn" HeaderText="EnterOn" 
                SortExpression="EnterOn" />
            <asp:CommandField ShowEditButton="True" ShowInsertButton="True" />
        </Fields>
    </asp:DetailsView>
    <asp:SqlDataSource ID="sdsWebGetMarketByID" runat="server" 
        ConnectionString="<%$ ConnectionStrings:DLDBConnectionString1 %>" 
        InsertCommand="prWebInsertMarket" InsertCommandType="StoredProcedure" 
        SelectCommand="prWebGetMarketByID" SelectCommandType="StoredProcedure" 
        UpdateCommand="prWebUpdateMarket" UpdateCommandType="StoredProcedure">
        <InsertParameters>
            <asp:Parameter Name="Name" Type="String" />
            <asp:Parameter Name="Description" Type="String" />
            <asp:Parameter Name="CategoryID" Type="Int32" />
        </InsertParameters>
        <SelectParameters>
            <asp:QueryStringParameter Name="ID" QueryStringField="ID" Type="Int32" />
        </SelectParameters>
        <UpdateParameters>
            <asp:Parameter Name="Name" Type="String" />
            <asp:Parameter Name="Description" Type="String" />
            <asp:Parameter Name="CategoryID" Type="Int32" />
            <asp:Parameter Name="ID" Type="Int32" />
        </UpdateParameters>
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="sdsWebGetCategory" runat="server" 
        ConnectionString="<%$ ConnectionStrings:DLDBConnectionString1 %>" 
        SelectCommand="SELECT [ID], [Name] FROM [tbCategory]"></asp:SqlDataSource>
</asp:Content>

ASPLDLMarketDetail.aspx.vb
Code:
Partial Class Management_ASPLDLMarketDetail
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Request.QueryString.Get("ID") IsNot Nothing Then
            DetailsView1.DefaultMode = DetailsViewMode.Edit
        End If
    End Sub

    Protected Sub DetailsView1_ItemInserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewInsertedEventArgs) Handles DetailsView1.ItemInserted
        EndEditing()
    End Sub

    Protected Sub DetailsView1_ItemUpdated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewUpdatedEventArgs) Handles DetailsView1.ItemUpdated
        EndEditing()
    End Sub

    Private Sub EndEditing()
        Response.Redirect("ASPLDLMarket.aspx")
    End Sub

End Class
Stored Procedures: prWebGetMarketByID
Code:
USE [DLDB]
GO
/****** Object:  StoredProcedure [dbo].[prWebGetMarketByID]    Script Date: 01/22/2015 18:25:06 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Name
-- Create date: 2 Jan 2015
-- Description:	Get Market By ID
-- =============================================
ALTER PROCEDURE [dbo].[prWebGetMarketByID] 
	-- Add the parameters for the stored procedure here
	@ID int 
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	SELECT [ID], [Name], [Description], [CategoryID], [EnterOn] FROM [tbMarket] 
		WHERE [ID] = @ID ORDER BY [Name]
		
END
Stored Procedures: prWebInsertMarket
Code:
USE [DLDB]
GO
/****** Object:  StoredProcedure [dbo].[prWebInsertMarket]    Script Date: 01/22/2015 18:27:10 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		htkwan
-- Create date: 2 Jan 2015
-- Description:	Insert Market
-- =============================================
ALTER PROCEDURE [dbo].[prWebInsertMarket] 
	-- Add the parameters for the stored procedure here
	@Name nvarchar(50), 
	@Description nvarchar(50),
	@CategoryID int
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT [tbMarket] ([Name], [Description], [CategoryID]) 
		VALUES (@Name, @Description, @CategoryID)
		
END
Stored Procedures: prWebUpdateMarket
Code:
USE [DLDB]
GO
/****** Object:  StoredProcedure [dbo].[prWebUpdateMarket]    Script Date: 01/22/2015 18:28:02 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		htkwan
-- Create date: 2 Jan 2015
-- Description:	Update Market
-- =============================================
ALTER PROCEDURE [dbo].[prWebUpdateMarket] 
	-- Add the parameters for the stored procedure here
	@Name nvarchar(50), 
	@Description nvarchar(50), 
	@CategoryID int, 
	@ID int 
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	UPDATE [tbMarket] SET [Name] = @Name, 
		[Description] = @Description,
		[CategoryID] = @CategoryID,
		[EnterOn] = GetDate() 
		WHERE [ID] = @ID

END
 
Old January 23rd, 2015, 06:15 PM
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,

Can you define it's not working in more detail? Do you get an error? What happens when you debug the code?

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 January 26th, 2015, 04:26 AM
Registered User
 
Join Date: Jan 2015
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 13: Displaying & Updating Data - With stored procedures?

Dear Imar,
I think i've made a mistake. I found a possible solution on https://www.youtube.com/watch?v=iqiQnEv2PQ4. Will try first, before i seek your advice. Thanks.
 
Old February 5th, 2015, 04:14 AM
Registered User
 
Join Date: Jan 2015
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 13: Displaying & Updating Data - With stored procedures?

Dear Imar,
I've managed to resolve the issue. I've used your "GridView" example. But for the "DetailsView", i use the "DetailsView" events, "Load" (to call a "Select" stored procedure), "ItemUpdating" (for Update), "ItemInserting" (for Insert), "ModeChanging", etc. It works okay.

I've read your book. I find it very easy to read & understand. Would you recommend a good book which teaches on how to program a web-application, instead of a web-site? Thanks.
 
Old February 5th, 2015, 04:22 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

>> Would you recommend a good book which teaches on how to program a web-application, instead of a web-site? Thanks.

If you're talking about the VS Project system, then most of it is identical. It's just how you create the initial site (through File | New Project instead of File | New Site) but after that many concepts are the same.

The book Professional ASP.NET 4.x has more details.

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 February 5th, 2015, 11:40 AM
Registered User
 
Join Date: Jan 2015
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dear Imar,
Thanks.





Similar Threads
Thread Thread Starter Forum Replies Last Post
chapter 13 , Bullets Reviews not displaying anjumk BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 5 October 7th, 2011 12:03 PM
Chapter 13 Drag & Drop Boboneil BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0 0 April 13th, 2010 01:01 PM
Chapter 12 Displaying and Updating Data bpl BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 4 November 25th, 2009 02:32 PM
Chapter 13 - Registering a Custom Data Extension MBryga BOOK: Professional SQL Server 2005 Reporting Services ISBN: 0-7645-8497-9 2 January 10th, 2008 11:49 AM
Data updating in Table & reflecting in report anukagni Access 5 May 31st, 2006 03:57 AM





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