is What?
进行数据的删选,然后汇总
使用App.config配置文件封装连接字符串,方便重复使用
—>添加App.conifg配置文件
—>Add : ConnectionString:
—>添加引用
What does it look like?
配置文件:
配置文件 只要引用就可以了,不需要自己写。
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<connectionStrings>
<add name="conStr" connectionString="Data Source=.;Initial Catalog=;User ID=;Password="/>
</connectionStrings>
</configuration>
使用sqlhelper
位置:DAL
//SqlNewChangeDAL.cs
using System.Collections.Generic;
using System.Data;
using Model;
using System.Data.SqlClient;
namespace LoginDAL //根据作用进行数据集的声明,便于调用
{
class SqlnewchargeDAL// : SevenLevels.IDAL //方法就是一种操作,按照一种操作,对操作进行封装
{
//public DataTable selectUser(UserInfo userInfo)
public IList<Model.UserInfo> selectUser(UserInfo userInfo) // 对实体层的字段的内容,更具自己的需要进行处理,这里是IList是一种泛型接口,可以按照索引来进行记录的搜索。
{
SqlHelper sqlhelper = new SqlHelper(); //实例化 SqlHelper,加载数据的连接配置文件
//可以同构赋值进行数据的修改。
//SqlParameter[] sqlparams = { new SqlParameter("@userID", userInfo.UserID), new SqlParameter("@userPwd", userInfo.UserPwd) };
SqlParameter[] sqlparams = { new SqlParameter("@userID", userInfo.UserID) };
//string sql = @"SELECT * FROM [User_Info] WHERE UserID=@UserID and UserPwd=@UserPwd";
string sql = @"SELECT * FROM [User_Info] WHERE UserID=@UserID";// 连接数据库之后进行的操作sQL查询语句。
DataTable table = sqlhelper.ExecuteQuery(sql, sqlparams, CommandType.Text);//返回 查询的结果
IList<Model.UserInfo> user = LoginDAL.ConvertHelper<Model.UserInfo>.ConvertToModel(table);
return user;
}
}
}
而 sqlHelper.cs 文件本身,很复杂
微软官方的类文件中有9中重载的方法
我现在还不是很懂,但是可以奉上大神们的总结博客: