当前位置:编程学习 > C#/ASP.NET >>

asp.net登陆界面

谁帮俺做个简单的会员登陆界面 后 能够后删除 会员

添加 查找 俺 会 不会删除 请帮按谢谢代码 写全些 昂 按 是初学者 刚学的 要求是 asp.net(C#) 而且得是三层架构的昂 麻烦了 万分感谢 sql数据库 我没有分了 不好意思昂

答案:模型层:

public class UserInfo()

{

public int id{get,set};

public string Name{get,set};

public string Pwd{get,set};

}

//数据库访问层

public class UserService()

{

public int Delete(int id){

private static readonly string CONNSTR="数据库连接字符串";

SqlConnection conn=new SqlConnection(CONNSTR);

conn.open();

SqlCommand command=new SqlCommand();

command.commandText="delete from 表名 where id="+id;

command.connection=conn;

return command.ExecuteNonQuery();

}

}

//业务逻辑层

public class UserManager()

{

public string Delete ( int id)

{

UserService userService=new UserService();

return userService.Delete(id)>0?"删除成功!":"删除失败!";

}

}

//表示层

选中要删除的会员,调用UserManager的Delete方法就OK啦!

删除会员,三层。首先你应该有个dbhelp类,

1.DBHelp类:

 

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace DAL
{
    public static class DBHelper
    {

        private static SqlConnection connection;
        public static SqlConnection Connection
        {
            get
            {
                string connectionString = "数据连接字符串":

                if (connection == null)
                {
                    connection = new SqlConnection(connectionString);
                    connection.Open();
                }
                else if (connection.State == System.Data.ConnectionState.Closed)
                {
                    connection.Open();
                }
                else if (connection.State == System.Data.ConnectionState.Broken)
                {
                    connection.Close();
                    connection.Open();
                }
                return connection;
            }
        }


        public static int ExecuteCommand(string safeSql)
        {
            SqlCommand cmd = new SqlCommand(safeSql, Connection);
            int result = cmd.ExecuteNonQuery();
            return result;
        }

        public static int ExecuteCommand(string sql, params SqlParameter[] values)
        {
            SqlCommand cmd = new SqlCommand(sql, Connection);
            cmd.Parameters.AddRange(values);
            return cmd.ExecuteNonQuery();
        }

        public static int GetScalar(string safeSql)
        {
            SqlCommand cmd = new SqlCommand(safeSql, Connection);
            int result = Convert.ToInt32(cmd.ExecuteScalar());
            return result;
        }

        public static int GetScalar(string sql, params SqlParameter[] values)
        {
            SqlCommand cmd = new SqlCommand(sql, Connection);
            cmd.Parameters.AddRange(values);
            int result = Convert.ToInt32(cmd.ExecuteScalar());
            return result;
        }
        public static string ReturnStringScalar(string safeSql)
        {
            SqlCommand cmd = new SqlCommand(safeSql, Connection);
            try
            {
                string result = cmd.ExecuteScalar().ToString();
                return result;
            }
            catch (Exception e)
            {
                throw e;
            }
        }

        public static SqlDataReader GetReader(string safeSql)
        {
            SqlCommand cmd = new SqlCommand(safeSql, Connection);
            SqlDataReader reader = cmd.ExecuteReader();
            return reader;
        }

        public static SqlDataReader GetReader(string sql, params SqlParameter[] values)
        {
            SqlCommand cmd = new SqlCommand(sql, Connection);
    

上一个:求一段ASP代码。
下一个:ASP编写程序的代码

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,