简体   繁体   English

使用ASP.NET,C#和SQL

[英]Working with ASP.NET, C# and SQL

I have been given the task to create a shop website that allows users to look at DVDs that are available in a shop page and then when they click on one they will be taken to a details page which will give more information dynamically about the DVD. 我的任务是创建一个商店网站,使用户可以查看商店页面中的DVD,然后单击它们时,将带他们到详细信息页面,该页面将动态提供有关DVD的更多信息。 I also have been given ac# file which contains a class called DVD. 我还得到了一个包含名为DVD的类的ac#文件。 I have so far got the webpages which I made in ASP.NET and that was easy enough to pull everything from the database and it all works fine but that has nothing to do with the DVD.cs file. 到目前为止,我已经获得了我在ASP.NET中制作的网页,并且很容易将所有内容从数据库中提取出来,并且一切正常,但与DVD.cs文件无关。

Am I missing something obvious? 我是否缺少明显的东西? I have to use this file which I will post below : 我必须使用此文件,该文件将在下面发布:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DVDs
{
class DVD
{
    public string Title
    {
        get;
        set;
    }

    public int Price
    {
        get;
        set;
    }

    public int YearReleased
    {
        get;
        set;
    }


    public string Desc
    {
        get;
        set;
    }

    public DVD(string title, int price, int yearReleased, string desc)
    {
        Title = title;
        Price = price;
        YearReleased = yearReleased;
        Desc = desc;

    }

    protected bool Save()
    {
        //add code to save to the database
        return true;
    }

    protected bool Load()
    {
        //add code to load from the database
        return true;
    }
}
}

Can someone please explain how I use these variables to link between the database and the .aspx file? 有人可以解释一下我如何使用这些变量在数据库和.aspx文件之间进行链接吗?

All help would be appreciated thanks 所有帮助将不胜感激谢谢

EDIT : Code tried so far 编辑 :到目前为止,代码已尝试

protected override void OnLoad(EventArgs e)
{
    base.OnLoad(e);
    if (this.IsPostBack)
    {
        PageAsyncTask pat = new PageAsyncTask(BeginAsync, EndAsync, null, null, true);
        RegisterAsyncTask(pat);
    }
}

private IAsyncResult BeginAsync(object sender, EventArgs e, AsyncCallback cb, object state)
{
    DVD dvd = new DVD();
}

either make it with MVC as it is already told or take a look at ASP.Net binding to link your DVD object to the UI. 要么使用已被告知的MVC进行制作,要么查看ASP.Net绑定以将DVD对象链接到UI。

This could be a good starting point: http://support.microsoft.com/kb/307860 这可能是一个很好的起点: http : //support.microsoft.com/kb/307860

使用实体框架将帮助您以非常简单的方式将类连接到数据库,但是要将类属性链接到ASP.NET .aspx文件,可以使用session["key"] = value

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM