
要求2:在ASP.NET中,构建用户页面,实现用户的添加、修改、删除、查询功能界面。 要求3:编写代码
要求2:在ASP.NET中,构建用户页面,实现用户的添加、修改、删除、查询功能界面要求3:编写代码,实现通过页面,往数据库中增加用户、修改用户、删除用户、查询用户信息功能...
要求2:在ASP.NET中,构建用户页面,实现用户的添加、修改、删除、查询功能界面
要求3:编写代码,实现通过页面,往数据库中增加用户、修改用户、删除用户、查询用户信息功能;增加用户的时候,要能实现对已存在用户的判断,不允许重复插入用户信息。 展开
要求3:编写代码,实现通过页面,往数据库中增加用户、修改用户、删除用户、查询用户信息功能;增加用户的时候,要能实现对已存在用户的判断,不允许重复插入用户信息。 展开
8个回答
展开全部
根据你的数据库自己做些修改
web.config设置:
------------------------------------------------------------------
<connectionStrings>
<add name="DBHelplerDbConnection" connectionString="database=sale;trusted_connection=true"/>
</connectionStrings>
----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using UserWebModel;
namespace UserWebDAL
{
public static class LoginUserService
{
//获取连接字符串
static string connectionString = ConfigurationManager.ConnectionStrings["DBHelplerDbConnection"].ConnectionString;
//插入输入
public static int InsertEntity(LoginUserInfo loginUserInfo)
{
string sql = "INSERT INTO [PopedomManagement].[dbo].[LoginUser] ([UserName],[UserPassword],[TypeId]) VALUES ('" + loginUserInfo.UserName + "','" + loginUserInfo.UserPassWord + "'," + loginUserInfo.UserTypeInfo.TypeId + ")";
int result = 0;
using (SqlConnection conn = new SqlConnection(connectionString))
{
if (conn.State != ConnectionState.Open)
conn.Open();
SqlCommand cmd = new SqlCommand(sql,conn);
result = Convert.ToInt32(cmd.ExecuteScalar());
conn.Close();
}
return result;
}
//查找数据
public static LoginUserInfo CheckUser(string userName,string userPass)
{
LoginUserInfo loginUserInfo = new LoginUserInfo();
string sql = string.Format("select * from dbo.LoginUser where UserName = '{0}' and UserPassword ='{1}'",userName,userPass);
using (SqlConnection conn = new SqlConnection(connectionString))
{
if (conn.State != ConnectionState.Open)
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataReader reader = cmd.ExecuteReader();
if (reader.Read())
{
loginUserInfo.UserId = (int)reader["UserId"];
loginUserInfo.UserName = (string)reader["UserName"];
loginUserInfo.UserPassWord = (string)reader["UserPassWord"];
loginUserInfo.UserTypeInfo = UserTypeService.SelectTypeById((int)reader["TypeId"]);
}
}
return loginUserInfo;
}
public static IList<LoginUserInfo> GetAll()
{
IList<LoginUserInfo> list = new List<LoginUserInfo>();
string sql = "select * from dbo.LoginUser";
SqlConnection conn = new SqlConnection(connectionString);
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
LoginUserInfo loginUserInfo = new LoginUserInfo();
loginUserInfo.UserId = (int)reader["UserId"];
loginUserInfo.UserName = (string)reader["UserName"];
loginUserInfo.UserPassWord = (string)reader["UserPassWord"];
loginUserInfo.UserTypeInfo = UserTypeService.SelectTypeById((int)reader["TypeId"]);
list.Add(loginUserInfo);
}
return list;
}
public static void DeleteUser(int id)
{
string sql = "delete dbo.LoginUser where UserId = " + id;
DBHelper.ExectuteCommand(sql);
}
}
}
web.config设置:
------------------------------------------------------------------
<connectionStrings>
<add name="DBHelplerDbConnection" connectionString="database=sale;trusted_connection=true"/>
</connectionStrings>
----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using UserWebModel;
namespace UserWebDAL
{
public static class LoginUserService
{
//获取连接字符串
static string connectionString = ConfigurationManager.ConnectionStrings["DBHelplerDbConnection"].ConnectionString;
//插入输入
public static int InsertEntity(LoginUserInfo loginUserInfo)
{
string sql = "INSERT INTO [PopedomManagement].[dbo].[LoginUser] ([UserName],[UserPassword],[TypeId]) VALUES ('" + loginUserInfo.UserName + "','" + loginUserInfo.UserPassWord + "'," + loginUserInfo.UserTypeInfo.TypeId + ")";
int result = 0;
using (SqlConnection conn = new SqlConnection(connectionString))
{
if (conn.State != ConnectionState.Open)
conn.Open();
SqlCommand cmd = new SqlCommand(sql,conn);
result = Convert.ToInt32(cmd.ExecuteScalar());
conn.Close();
}
return result;
}
//查找数据
public static LoginUserInfo CheckUser(string userName,string userPass)
{
LoginUserInfo loginUserInfo = new LoginUserInfo();
string sql = string.Format("select * from dbo.LoginUser where UserName = '{0}' and UserPassword ='{1}'",userName,userPass);
using (SqlConnection conn = new SqlConnection(connectionString))
{
if (conn.State != ConnectionState.Open)
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataReader reader = cmd.ExecuteReader();
if (reader.Read())
{
loginUserInfo.UserId = (int)reader["UserId"];
loginUserInfo.UserName = (string)reader["UserName"];
loginUserInfo.UserPassWord = (string)reader["UserPassWord"];
loginUserInfo.UserTypeInfo = UserTypeService.SelectTypeById((int)reader["TypeId"]);
}
}
return loginUserInfo;
}
public static IList<LoginUserInfo> GetAll()
{
IList<LoginUserInfo> list = new List<LoginUserInfo>();
string sql = "select * from dbo.LoginUser";
SqlConnection conn = new SqlConnection(connectionString);
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
LoginUserInfo loginUserInfo = new LoginUserInfo();
loginUserInfo.UserId = (int)reader["UserId"];
loginUserInfo.UserName = (string)reader["UserName"];
loginUserInfo.UserPassWord = (string)reader["UserPassWord"];
loginUserInfo.UserTypeInfo = UserTypeService.SelectTypeById((int)reader["TypeId"]);
list.Add(loginUserInfo);
}
return list;
}
public static void DeleteUser(int id)
{
string sql = "delete dbo.LoginUser where UserId = " + id;
DBHelper.ExectuteCommand(sql);
}
}
}
本回答被提问者采纳

你对这个回答的评价是?
展开全部
其实这些功能不难,只要你肯动手。多思考!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
纯粹的打酱油的,你网上找找多了去了。这都是实现最基本的功能的,楼主懒的够可以的了。这样子不适合做开发的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询