首页 > 代码库 > web登陆,增删改加分页。

web登陆,增删改加分页。

这段时间做了登陆页面和对数据库的增删改。传值用了cokkies.

首先是登陆页面:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="denglu.aspx.cs" Inherits="denglu" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<style type="text/css">
.div1 {
position: absolute;
width: 400px;
height: 300px;
background-color: white;
box-shadow: 0px 0px 15px #808080;
left: 50%;
margin-left: -200px;
top: 50%;
margin-top: -170px;
text-align: center;
line-height: 40px;
background-image :url(img/1.jpg) ;
background-repeat :no-repeat ;
color :red ;
}

#TextBox1 {
margin-top: 100px;
}

#Button1 {
width: 100px;
height: 30px;
border: 0px;
background-color: pink ;
color: white;

}

#Label1 {
color: red;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div class="div1">
用户名:
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
密 码:
<asp:TextBox ID="TextBox2" TextMode="Password" runat="server"></asp:TextBox><br />
<asp:CheckBox ID="CheckBox1" runat="server" Text="三天内保持登录状态" /><br />
<asp:Button ID="Button1" runat="server" Text="登 录" /><br />
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>

</div>
</form>
</body>
</html>

后台代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class denglu : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Button1.Click += Button1_Click;
}

void Button1_Click(object sender, EventArgs e)
{
//获取用户名密码
string uname = TextBox1.Text;
string pwd = TextBox2.Text;

//验证用户名密码
Users u = new UsersData().SelectUser(uname, pwd);

Label1.Text = "";
//执行相关操作
if (u != null)
{
Response.Cookies["user"].Value = http://www.mamicode.com/u.UserName ;

if (CheckBox1.Checked)
{
Response.Cookies["user"].Expires = DateTime.Now.AddDays(3);
}

Response.Redirect("Default.aspx");
}
else
{
Label1.Text = "用户名或密码错误!!!";
}

}
}

总页面:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<style type ="text/css" >
.shuju {
width :260px;
margin :5px 5px;
background-color :pink ;
float :left ;
}
.shuju:hover {
background-color :blue ;
}

</style>
<script >
function open() {

}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:Button ID="Button1" runat="server" Text="退出登录" />
<div style ="width:1080px;margin :0 auto ;background-color :gray ;">

<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate >
<div class ="shuju">
Ids: <%#Eval("Ids") %> <br/>
编号: <%#Eval ("Ucode") %> <br />
用户名: <%#Eval ("UserName") %> <br />
密码: <%#Eval ("PassWord") %> <br/>
昵称: <%#Eval ("NickName") %><br/>
性别: <%#Eval ("SexStr") %><br/>
生日: <%#Eval ("BirthdayStr") %><br/>
民族: <%#Eval ("NationName") %><br/>
<a href ="http://www.mamicode.com/update.aspx?id=<%#Eval("Ids") %>" >修改</a>
<a href ="http://www.mamicode.com/delte.aspx?id=<%#Eval("Ids") %>" onclick ="return confirm(‘是否删除?‘);">删除</a>
</div>

</ItemTemplate>
</asp:Repeater>
<div style =" clear :both ; "></div>
</div>
<div style="margin:0 auto;width :1082px; ">
<a href ="http://www.mamicode.com/insert.aspx" target="_blank" >增加</a>

</div>
<div style="width: 100%; text-align: center; line-height: 30px;">
当前第[
<asp:Label ID="lab_NowPageNumber" runat="server" Text="1"></asp:Label>
]页
&nbsp;&nbsp;共[
<asp:Label ID="lab_MaxPageNumber" runat="server" Text="1"></asp:Label>
]页<br />
<asp:Button ID="btn_First" runat="server" Text="首页" />
<asp:Button ID="btn_Prev" runat="server" Text="上一页" />
<asp:Button ID="btn_Next" runat="server" Text="下一页" />
<asp:Button ID="btn_Last" runat="server" Text="尾页" />
<asp:DropDownList ID="dr_drop" AutoPostBack="true" runat="server"></asp:DropDownList>
<asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox>
<asp:Button ID="Button2" runat="server" Text="跳转" />
</div>
</form>
</body>
</html>

后台代码里面包括了分页代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
int PageCount = 4;//每页显示条数
protected void Page_Load(object sender, EventArgs e)
{

Button1.Click += Button1_Click;
TextBox1.TextChanged += TextBox1_TextChanged;
if (Request.Cookies["user"] != null)
{
Response.Write(Request.Cookies["user"].Value + ",欢迎你!");
}
else
{
Response.Redirect("denglu.aspx");
}



btn_Last.Click += btn_Last_Click;
btn_Next.Click += btn_Next_Click;
btn_Prev.Click += btn_Prev_Click;
btn_First.Click += btn_First_Click;
Button2.Click += Button2_Click;
dr_drop.SelectedIndexChanged += dr_drop_SelectedIndexChanged;

 

if (!IsPostBack)
{


Repeater1.DataSource = new UsersData().Select(1, PageCount);
Repeater1.DataBind();
lab_MaxPageNumber.Text = getMaxNumber().ToString();
btn_First.Enabled = false;
btn_Prev.Enabled = false;

for (int i = 1; i <= Convert.ToInt32(lab_MaxPageNumber.Text); i++)
{
dr_drop.Items.Add(new ListItem(i.ToString(), i.ToString()));
}


}


}

void TextBox1_TextChanged(object sender, EventArgs e)
{






}

void Button1_Click(object sender, EventArgs e)
{
Response.Cookies["user"].Expires = DateTime.Now.AddDays(-10);
Response.Redirect("denglu.aspx");
}
void Button2_Click(object sender, EventArgs e)
{

int a = Convert.ToInt32(TextBox1.Text);
PageDataBind(a);



}
void dr_drop_SelectedIndexChanged(object sender, EventArgs e)
{
int a = Convert.ToInt32(dr_drop.SelectedValue);
PageDataBind(a);
}

public int getMaxNumber()
{
int end = 1;
//(数据总条数/每页显示条数)取上限
int allCount = new UsersData ().SelectAll().Count ;

decimal a = Convert.ToDecimal(allCount) / PageCount;

end = Convert.ToInt32(Math.Ceiling(a));

return end;
}

void btn_First_Click(object sender, EventArgs e)
{
int a = 1;
PageDataBind(a);
btn_First.Enabled = false;
btn_Prev.Enabled = false;
btn_Next.Enabled = true;
btn_Last.Enabled = true;
}

void btn_Prev_Click(object sender, EventArgs e)
{
int a = Convert.ToInt32(lab_NowPageNumber.Text) - 1;
if (a > 0)
{
PageDataBind(a);
}
if (a == 1)
{
btn_First.Enabled = false;
btn_Prev.Enabled = false;
}
btn_Next.Enabled = true;
btn_Last.Enabled = true;
}

void btn_Next_Click(object sender, EventArgs e)
{
int a = Convert.ToInt32(lab_NowPageNumber.Text) + 1;
if (a <= Convert.ToInt32(lab_MaxPageNumber.Text))
{
PageDataBind(a);
}
btn_First.Enabled = true;
btn_Prev.Enabled = true;
if (a == Convert.ToInt32(lab_MaxPageNumber.Text))
{
btn_Next.Enabled = false;
btn_Last.Enabled = false;
}

}

void btn_Last_Click(object sender, EventArgs e)
{
int a = Convert.ToInt32(lab_MaxPageNumber.Text);
PageDataBind(a);
btn_Next.Enabled = false;
btn_Last.Enabled = false;
btn_First.Enabled = true;
btn_Prev.Enabled = true;
}

public void PageDataBind(int a)
{
Repeater1.DataSource = new UsersData ().Select(a, PageCount);
Repeater1.DataBind();
lab_NowPageNumber.Text = a.ToString();
}
}

增添页面:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="insert.aspx.cs" Inherits="insert" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">


<div>
<asp:Literal ID="Literal1" runat="server"></asp:Literal>
编号: <asp:TextBox ID="TextBox1" runat="server" Enabled ="false" ></asp:TextBox><br />
用户名: <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br />
密码: <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox><br />
昵称: <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox><br />
性别: <asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatDirection ="Horizontal" >
<asp:ListItem Value ="http://www.mamicode.com/True" Selected ="True" >男</asp:ListItem>
<asp:ListItem Value ="http://www.mamicode.com/False">女</asp:ListItem>
</asp:RadioButtonList><br />
生日:

<asp:DropDownList ID="DropDownList1" runat="server"></asp:DropDownList>年
<asp:DropDownList ID="DropDownList2" runat="server"></asp:DropDownList>月
<asp:DropDownList ID="DropDownList3" runat="server"></asp:DropDownList>日<br/>
民族: <asp:DropDownList ID="DropDownList4" runat="server"></asp:DropDownList> <br />

<asp:Button ID="Button1" runat="server" Text="增添" />

</div>
</form>
</body>
</html>

 后台代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class insert : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Button1.Click += Button1_Click;
if (!IsPostBack)
{
Users u = new Users();
u.Ucode = new UsersData().NewUcode();
TextBox1.Text = u.Ucode;
DropDownList4.DataSource = new UserNationData().SelectAll();
DropDownList4.DataTextField = "NationName";
DropDownList4.DataValueField = "NationCode";
DropDownList4.DataBind();
DropDownList4.SelectedValue = http://www.mamicode.com/u.Nation;
}


for (int i = DateTime.Now.Year; i > 1999; i--) //时间赋值
{
ListItem li = new ListItem(i.ToString(), i.ToString());
DropDownList1.Items.Add(li);
}
for (int i = 1; i < 12; i++)
{
ListItem li = new ListItem(i.ToString(), i.ToString());
DropDownList2.Items.Add(li);
}
for (int i = 1; i < 32; i++)
{
ListItem li = new ListItem(i.ToString(), i.ToString());
DropDownList3.Items.Add(li);
}
}

void Button1_Click(object sender, EventArgs e)
{

Users u = new Users();
u.Ucode = TextBox1.Text;
u.UserName = TextBox2.Text;
u.PassWord = TextBox3.Text;
u.NickName = TextBox4.Text;
u.Sex = Convert.ToBoolean(RadioButtonList1.SelectedValue);
u.Birthday = Convert.ToDateTime(DropDownList1.SelectedValue + "-" + DropDownList2.SelectedValue + "-" + DropDownList3.SelectedValue);
u.Nation = DropDownList4.SelectedValue;

new UsersData().InsertUser(u);
Literal1.Text = "<script>alert(‘添加成功!‘);window.location.href=http://www.mamicode.com/‘default.aspx‘;</script>";

}
}

修改页面:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="update.aspx.cs" Inherits="update" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Literal ID="Literal1" runat="server"></asp:Literal>
编号: <asp:TextBox ID="TextBox1" runat="server" Enabled ="false" ></asp:TextBox><br />
用户名: <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br />
密码: <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox><br />
昵称: <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox><br />
性别: <asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatDirection ="Horizontal" >
<asp:ListItem Value ="http://www.mamicode.com/True">男</asp:ListItem>
<asp:ListItem Value ="http://www.mamicode.com/False">女</asp:ListItem>
</asp:RadioButtonList><br />
生日:

<asp:DropDownList ID="DropDownList1" runat="server"></asp:DropDownList>年
<asp:DropDownList ID="DropDownList2" runat="server"></asp:DropDownList>月
<asp:DropDownList ID="DropDownList3" runat="server"></asp:DropDownList>日<br/>
民族: <asp:DropDownList ID="DropDownList4" runat="server"></asp:DropDownList> <br />

<asp:Button ID="Button1" runat="server" Text="修改" />
</div>
</form>
</body>
</html>

后台代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class update : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Button1.Click += Button1_Click;
if (!IsPostBack)
{
string ss = Request["id"];
Users u = new UsersData().SelectIds(ss);
TextBox1.Text = u.Ucode;
TextBox2.Text = u.UserName;
TextBox3.Text = u.PassWord;
TextBox4.Text = u.NickName;
RadioButtonList1.SelectedValue =http://www.mamicode.com/u.Sex .ToString ();
DropDownList1.Items .Add ( u.Birthday.Year.ToString ()) ;
DropDownList2.Items.Add(u.Birthday.Month .ToString());
DropDownList3.Items.Add(u.Birthday.Day.ToString());

DropDownList4.DataSource = new UserNationData (). SelectAll();
DropDownList4.DataTextField = "NationName";
DropDownList4.DataValueField = "NationCode";
DropDownList4.DataBind();
DropDownList4.SelectedValue = http://www.mamicode.com/u.Nation;



for (int i = DateTime.Now.Year; i > 1999; i--) //时间赋值
{
ListItem li = new ListItem(i.ToString(), i.ToString());
DropDownList1.Items.Add(li);
}
for (int i = 1; i < 12; i++)
{
ListItem li = new ListItem(i.ToString(), i.ToString());
DropDownList2.Items.Add(li);
}
for (int i = 1; i < 32; i++)
{
ListItem li = new ListItem(i.ToString(), i.ToString());
DropDownList3.Items.Add(li);
}

}
}

void Button1_Click(object sender, EventArgs e)
{

Users u = new Users();
u.Ucode = TextBox1.Text;
u.UserName = TextBox2.Text;
u.PassWord = TextBox3.Text;
u.NickName = TextBox4.Text;
u.Sex =Convert .ToBoolean ( RadioButtonList1.SelectedValue);
u.Birthday = Convert.ToDateTime(DropDownList1 .SelectedValue +"-"+DropDownList2 .SelectedValue +"-"+DropDownList3 .SelectedValue );
u.Nation = DropDownList4.SelectedValue;
bool ok = new UsersData().UpdateUser(u);
if (ok)
{

}
Literal1.Text = "<script>alert(‘修改成功!‘);window.location.href=http://www.mamicode.com/‘default.aspx‘;</script>";

}
}

删除后台代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class delete : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string s = Request ["id"];
new UsersData().Delet(s );
Response.Write("<script>alert(‘删除成功!‘);window.location.href=http://www.mamicode.com/‘default.aspx‘;</script>");

}


}

                                                                                            实体类和数据访问类建在APP_Code文件夹下面:

                                                                                       UserNation:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// UserNation 的摘要说明
/// </summary>
public class UserNation
{
public UserNation()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
private string _NationCode;

public string NationCode
{
get { return _NationCode; }
set { _NationCode = value; }
}
private string _NationName;

public string NationName
{
get { return _NationName; }
set { _NationName = value; }
}
}

 

                                                                            UserNationData:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
/// <summary>
/// UserNationData 的摘要说明
/// </summary>
public class UserNationData
{
SqlConnection conn;
SqlCommand cmd;
public UserNationData()
{
conn = new SqlConnection("server=.;database=Data0504;user=sa;pwd=123");
cmd = conn.CreateCommand();
}
public string SelectNation(string nc)
{
string s = "无数据";
cmd.CommandText = "select *from UserNation where NationCode = @a";
cmd.Parameters.Clear();
cmd.Parameters.AddWithValue("@a", nc);
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();

if (dr.HasRows)
{
dr.Read();
s = dr["NationName"].ToString();
}

conn.Close();
return s;
}

public string SelectNationCode(string nn)
{
string end = "null";
cmd.CommandText = "select *from UserNation where NationName like @a";
cmd.Parameters.Clear();
cmd.Parameters.Add("@a", "%" + nn + "%");
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
dr.Read();
end = dr["NationCode"].ToString();
}
conn.Close();
return end;
}
public List<UserNation> SelectAll()
{
List<UserNation> nlist = new List<UserNation>();

cmd.CommandText = "select *from UserNation";
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
UserNation un = new UserNation();
un.NationCode = dr[0].ToString();
un.NationName = dr[1].ToString();
nlist.Add(un);
}
conn.Close();
return nlist;
}
}

 

                                                                                      Users:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;

/// <summary>
/// Users 的摘要说明
/// </summary>
public class Users
{
public Users()
{

}
public int Ids { get; set; }
public string Ucode { get; set; }
public string UserName { get; set; }
public string PassWord { get; set; }
public string NickName { get; set; }
public bool Sex { get; set; }
public string SexStr
{
get
{
return Sex ? "男" : "女";
}
}

 

public DateTime Birthday { get; set; }
public string Nation { get; set; }

public string BirthdayStr
{
get { return Birthday.ToString("yyyy年MM月dd日"); }
}

public string NationName
{
get
{
return new UserNationData().SelectNation(Nation);
}
}

}

                                                                                                                  UsersData:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;

/// <summary>
/// UsersData 的摘要说明
/// </summary>
public class UsersData
{
SqlConnection conn = null;
SqlCommand cmd = null;
public UsersData()
{
conn = new SqlConnection("server=.;database=Data0504;user=sa;pwd=123");
cmd = conn.CreateCommand();
}

public List<Users> SelectAll()
{
List<Users> ulist = new List<Users>();

cmd.CommandText = "select *from Users";
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
Users u = new Users();
u.Ids =Convert .ToInt32 (dr["Ids"]);
u.Ucode = dr["Ucode"].ToString();
u.UserName = dr["UserName"].ToString();
u.PassWord = dr["PassWord"].ToString();
u.NickName = dr["NickName"].ToString();
u.Sex = Convert.ToBoolean(dr["Sex"]);
u.Birthday = Convert.ToDateTime(dr["Birthday"]);
u.Nation = dr["Nation"].ToString();

ulist.Add(u);
}
conn.Close();
return ulist;
}

public void InsertUser(Users u)
{
cmd.CommandText = "insert into Users values(@a,@b,@c,@d,@e,@f,@g)";
cmd.Parameters.Clear();
cmd.Parameters.AddWithValue("@a",u.Ucode);
cmd.Parameters.AddWithValue("@b", u.UserName);
cmd.Parameters.AddWithValue("@c", u.PassWord);
cmd.Parameters.AddWithValue("@d", u.NickName);
cmd.Parameters.AddWithValue("@e", u.Sex);
cmd.Parameters.AddWithValue("@f", u.Birthday);
cmd.Parameters.AddWithValue("@g", u.Nation);

conn.Open();
cmd.ExecuteNonQuery();
conn.Close();


}
public string NewUcode()
{
string s = "生成失败!";

cmd.CommandText = "select *from Users Order by Ucode desc";
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
dr.Read();

string code = dr["Ucode"].ToString();
int a = Convert.ToInt32(code.Substring(1));
a++;
s = "U" + a.ToString("000");
}

conn.Close();
return s;
}
public bool UpdateUser(Users u)
{
bool ok = false;

cmd.CommandText = "update Users set PassWord = @a, NickName=@b,Sex=@c ,Birthday=@e,Nation = @d where Ucode = @f";
cmd.Parameters.Clear();
cmd.Parameters.AddWithValue("@a", u.PassWord);
cmd.Parameters.AddWithValue("@b", u.NickName);
cmd.Parameters.AddWithValue("@c", u.Sex);
cmd.Parameters.AddWithValue("@e", u.Birthday);
cmd.Parameters.AddWithValue("@d", u.Nation);
cmd.Parameters.AddWithValue("@f", u.Ucode);


conn.Open();

int count = cmd.ExecuteNonQuery();
if (count > 0)
{
ok = true;
}

conn.Close();
return ok;
}
public Users SelectUser(string uc)
{
Users u = null;
cmd.CommandText = "select *from Users where Ucode = @a";
cmd.Parameters.Clear();
cmd.Parameters.AddWithValue("@a", uc);

conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
dr.Read();
u = new Users();
u.Ids =Convert .ToInt32 ( dr["Ids"]);
u.Ucode = dr["Ucode"].ToString();
u.UserName = dr["UserName"].ToString();
u.PassWord = dr["PassWord"].ToString();
u.NickName = dr["NickName"].ToString();
u.Sex = Convert.ToBoolean(dr["Sex"]);
u.Birthday = Convert.ToDateTime(dr["Birthday"]);
u.Nation = dr["Nation"].ToString();
}
conn.Close();
return u;
}
public bool Deleteuser(Users u)
{
bool ok = false;
cmd.CommandText = "delete from Users where Ucode=@a ";
cmd.Parameters.Clear();
cmd.Parameters.AddWithValue("@a", u.Ucode);
conn.Open();
int count = cmd.ExecuteNonQuery();
if (count > 0)
{
ok = true;
}

conn.Close();
return ok;

}
public void Delet(string s) {
cmd.CommandText = "delete from Users where Ids=@a ";
cmd.Parameters.Clear();
cmd.Parameters.AddWithValue("@a", s);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();

}
public Users SelectIds(string uc)
{
Users u = null;
cmd.CommandText = "select *from Users where Ids = @a";
cmd.Parameters.Clear();
cmd.Parameters.AddWithValue("@a", uc);

conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
dr.Read();
u = new Users();
u.Ids = Convert.ToInt32(dr["Ids"]);
u.Ucode = dr["Ucode"].ToString();
u.UserName = dr["UserName"].ToString();
u.PassWord = dr["PassWord"].ToString();
u.NickName = dr["NickName"].ToString();
u.Sex = Convert.ToBoolean(dr["Sex"]);
u.Birthday = Convert.ToDateTime(dr["Birthday"]);
u.Nation = dr["Nation"].ToString();
}
conn.Close();
return u;
}
public Users SelectUser(string uname, string pwd)
{
Users u = null;

cmd.CommandText = "select *from Users where UserName = @a and PassWord = @b";
cmd.Parameters.Clear();
cmd.Parameters.AddWithValue("@a", uname);
cmd.Parameters.AddWithValue("@b", pwd);
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
u = new Users();
u.Ids = Convert.ToInt32(dr[0]);
u.Ucode = dr[1].ToString();
u.UserName = dr[2].ToString();
u.PassWord = dr[3].ToString();
u.NickName = dr[4].ToString();
u.Sex = Convert.ToBoolean(dr[5]);
u.Birthday = Convert.ToDateTime(dr[6]);
u.Nation = dr[7].ToString();
}
conn.Close();
return u;
}
public List<Users> Select(int NowNumber, int Count)
{
List<Users> clist = new List<Users>();
cmd.CommandText = "select top " + Count + " *from Users where Ids not in(select top " + ((NowNumber - 1) * Count) + " Ids from Users)";

conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
Users u = new Users();
u.Ids = Convert.ToInt32(dr["Ids"]);
u.Ucode = dr["Ucode"].ToString();
u.UserName = dr["UserName"].ToString();
u.PassWord = dr["PassWord"].ToString();
u.NickName = dr["NickName"].ToString();
u.Sex = Convert.ToBoolean(dr["Sex"]);
u.Birthday = Convert.ToDateTime(dr["Birthday"]);
u.Nation = dr["Nation"].ToString();

clist.Add(u);

}
conn.Close();
return clist;
}

}

web登陆,增删改加分页。