using System;
using System.Collections.Generic;
//using System.Linq;
using System.Web;
public class Dao
{
private static string ConnectionString = "Data Source=.;Initial Catalog=mydata;User ID=sa;Password=Abcdefg1";
public Dao()
{
}
public static bool login(string username, string userpass)
{
bool b = false;
using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(ConnectionString))
{
System.Data.SqlClient.SqlCommand comm = conn.CreateCommand();
comm.CommandText = "select count(*) from t_user where username = @username and userpass = @userpass";
comm.Parameters.AddWithValue("username", username);
comm.Parameters.AddWithValue("userpass", userpass);
conn.Open();
object o = comm.ExecuteScalar();
int i = Convert.ToInt32(o);
if (i > 0)
{
b = true;
}
}
return b;
}
public static void BangDingUser(System.Web.UI.WebControls.GridView gv)
{
using (System.Web.UI.WebControls.SqlDataSource sds = new System.Web.UI.WebControls.SqlDataSource(Dao.ConnectionString, "select * from t_user order by username asc"))
{
gv.DataSource = sds;
gv.DataBind();
}
}
public static void GridViewUser(System.Web.UI.WebControls.GridView gv)
{
gv.Caption = "用户表";
gv.EmptyDataText = "用户表数据为空";
gv.EmptyDataRowStyle.BackColor = System.Drawing.Color.Red;
gv.GridLines = System.Web.UI.WebControls.GridLines.None;
gv.AllowPaging = true;
gv.HeaderStyle.BackColor = System.Drawing.Color.Green;
gv.A
file:///C:\Users\j\Desktop\WebSite\App_Code\Dao.cs
本文详细解析了在Web应用程序中,如何使用C#实现DAO层,包括文件 Dao.cs 的内容,讨论了其在数据访问和业务逻辑层交互中的关键作用,以及常见的设计模式和最佳实践。
摘要由CSDN通过智能技术生成