using System;using System.Collections.Generic;using System.Linq;using System.Web;namespace 实体类{ public class User { public int Id { get; set; } public string UserName { get; set; } public int Age { get; set; } public int Gender { get; set; } }}
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Data;namespace 实体类.ModelService{ public class UserService { public static List SelectDataToEntity() { //通过查询数据库,将获取到的数据转换成一个list List list = SqlHelper.SelectDataToList("select * from T_User"); return list; } }}
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using 实体类.ModelService;namespace 实体类{ public partial class WebForm1 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { //将获取到的list(List lsit)存放到 Session里。然后可以在WebForm1.aspx页面中来遍历这个list 从而取到实体类的数据 Session.Add("User", UserService.SelectDataToEntity()); } }}
<4>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="实体类.WebForm1" %>
声明:本网页内容旨在传播知识,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。TEL:177 7030 7066 E-MAIL:11247931@qq.com