c# question im stuck on.

.net , csharp , error Manchester, United Kingdom
  • 8 years ago

    Hi guys.Newbie here. Im doing my first project with C# and asp.net 3.5 and i cant get past the same error:

    **Server Error in '/' Application

    Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: CS1061: 'BookPic' does not contain a definition for 'UserName' and no extension method 'UserName' accepting a first argument of type 'BookPic' could be found (are you missing a using directive or an assembly reference?)

    Source Error:

    Line 28: { Line 29: BookPic myBookPic = (BookPic)e.NewObject; Line 30: myBookPic.UserName = User.Identity.Name; Line 31: } Line 32: }

    Source File: c:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\WebSites\SALFORDBOOKSHOP\NewBookPics.aspx.cs Line: 30 **

    Im not sure why it is telling me this as my table BookPic does contain UserName. Im not sure how else to intepretate the error message. Here is my code:

    NewBookPics.aspx:

    <%@ Page Language="C#" MasterPageFile="~/MasterPages/MasterPage.master" AutoEventWireup="true" CodeFile="NewBookPics.aspx.cs" Inherits="NewBookPics" Title="New Book Pics" %>
    
    <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    </asp:Content>
    
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
        <asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True" 
            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="Name" HeaderText="Name" SortExpression="Name" />
                <asp:CommandField ShowInsertButton="True" />
            </Fields>
        </asp:DetailsView>
        <asp:LinqDataSource ID="LinqDataSource1" runat="server" 
            ContextTypeName="SalfordStudentBooksDataContext" EnableInsert="True" 
            oninserted="LinqDataSource1_Inserted"
            oninserting="LinqDataSource1_Inserting" TableName="BookPics">
        </asp:LinqDataSource>
    </asp:Content>
    

    Code Behind File: using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq;

    public partial class NewBookPics : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
    
        }
        protected void LinqDataSource1_Inserted(object sender, LinqDataSourceStatusEventArgs e)
        {
            BookPic myBookPic = (BookPic)e.Result;
            Response.Redirect(string.Format("PurchaseBooks.aspx?BookPicId={0}",
                                         myBookPic.Id.ToString()));
        }
    
        protected void LinqDataSource1_Inserting(object sender, LinqDataSourceInsertEventArgs e)
        {
            BookPic myBookPic = (BookPic)e.NewObject;
            myBookPic.UserName = User.Identity.Name;
        }
    }
    

    Thanks if anyone can help me with this one guys.Cheers!

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“In order to understand recursion, one must first understand recursion.”