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 October 17th, 2009, 04:41 AM
Authorized User
 
Join Date: Oct 2009
Posts: 16
Thanks: 8
Thanked 0 Times in 0 Posts
Default Inserting Username into Database

Morning Imar

I am creating a page that will allow users to insert a review and I am mirroring page NewPhotoAlbum.aspx.

At present the details view will insert a record but not the username.

VWD does not pick any errors when compiling the code.

Below is my code.

Code:
 protected void LinqDataSource1_Inserting(object sender, LinqDataSourceInsertEventArgs e)
  {
      Review myReview = (Review)e.NewObject;
      myReview.UserName = User.Identity.Name;
  }
Code:
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" Runat="Server">
  <h1>Hi there visitor create your photo book</h1>
    <p>
        <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" 
            DataKeyNames="Id" DataSourceID="LinqDataSource1" DefaultMode="Insert" 
            Height="50px" Width="125px">
            <Fields>
                <asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False" 
                    ReadOnly="True" SortExpression="Id" />
                <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
                <asp:BoundField DataField="Summary" HeaderText="Summary" 
                    SortExpression="Summary" />
                <asp:BoundField DataField="Body" HeaderText="Body" SortExpression="Body" />
                <asp:BoundField DataField="GenreId" HeaderText="GenreId" 
                    SortExpression="GenreId" />
                <asp:CheckBoxField DataField="Authorized" HeaderText="Authorized" 
                    SortExpression="Authorized" />
                <asp:BoundField DataField="CreateDateTime" HeaderText="CreateDateTime" 
                    SortExpression="CreateDateTime" />
                <asp:BoundField DataField="UpdateDateTime" HeaderText="UpdateDateTime" 
                    SortExpression="UpdateDateTime" />
                <asp:CommandField ShowInsertButton="True" />
            </Fields>
        </asp:DetailsView>
        <asp:LinqDataSource ID="LinqDataSource1" runat="server" 
            ContextTypeName="iGigDataContext" EnableInsert="True" TableName="Reviews">
        </asp:LinqDataSource>
    </p>
  </asp:Content>
If you could take a look at my code that would be great.

Thanks

Hippo
 
Old October 17th, 2009, 06:08 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,

Take a look at this:

Quote:
<asp:LinqDataSource ID="LinqDataSource1" runat="server" ContextTypeName="iGigDataContext" EnableInsert="True" TableName="Reviews">
</asp:LinqDataSource>
There is no Inserting handler that points to LinqDataSource1_Inserting

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!
The Following User Says Thank You to Imar For This Useful Post:
bigyawn_hippo (October 17th, 2009)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Pass UserName to Database sterreyl ASP.NET 2.0 Basics 0 March 11th, 2007 11:26 AM
Username is not accepted in to the database madhusrp ASP.NET 1.0 and 1.1 Professional 3 March 19th, 2006 12:19 AM
inserting into database shieldsteven VS.NET 2002/2003 0 November 11th, 2004 07:44 PM
inserting into database shieldsteven VS.NET 2002/2003 8 October 20th, 2004 05:33 PM
Inserting into database ZiqXx C# 6 July 5th, 2004 04:13 AM





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