C# 例子1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace Com.Dys.Model
{
class User
{
private int id;
private string username;
private string password; public int Id
{
get { return this.id; }
set { this.id = value; }
} public string Username
{
get { return this.username; }
set { this.username = value; }
} public string Password
{
get { return this.password; }
set { this.password = value; }
} public User()
{
} public User(int id, string username, string password)
{
this.id = id;
this.username = username;
this.password = password;
}
}
}
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace Com.Dys.Utils
{
class DBUtils
{
public static SqlDataReader GetSQLDataReader(string Sql)
{
try
{
string SqlConnection = "server=127.0.0.1;database=dingyingsi;uid=sa;pwd=dys123;";
//windows身份验证
//string sqlconn = "server=(local);database=keede1228;integrated security=SSPI;";
SqlConnection Connection = new SqlConnection(SqlConnection);
Connection.Open();
SqlCommand Command = new SqlCommand(Sql, Connection);
SqlDataReader Reader = Command.ExecuteReader();
return Reader;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.ReadLine();
}
return null;
}
}
}
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Com.Dys.Model;
using Com.Dys.Utils;
using System.Data.SqlClient; namespace Demo01
{
class Demo
{
static void Main(string[] args)
{
string Sql = "select id, username, password from [user]";
SqlDataReader Reader = DBUtils.GetSQLDataReader(Sql);
IEnumerable Users = Encapsulate(Reader);
foreach(User user in Users)
{
Console.WriteLine("id = {0}", user.Id);
Console.WriteLine("username = {0}", user.Username);
Console.WriteLine("password = {0}", user.Password);
}
Console.ReadLine();
} static IEnumerable Encapsulate(SqlDataReader Reader)
{
ArrayList al = new ArrayList();
User user = null;
if (Reader == null)
{
return null;
} while (Reader.Read())
{
user = new User();
user.Id = (int)Reader["id"];
user.Username = (string)Reader["username"];
user.Password = (string)Reader["password"]; al.Add(user);
}
return al;
}
}
}

C# 例子1的更多相关文章
- SQLServer地址搜索性能优化例子
这是一个很久以前的例子,现在在整理资料时无意发现,就拿出来再改写分享. 1.需求 1.1 基本需求: 根据输入的地址关键字,搜索出完整的地址路径,耗时要控制在几十毫秒内. 1.2 数据库地址表结构和数 ...
- C#+HtmlAgilityPack+XPath带你采集数据(以采集天气数据为例子)
第一次接触HtmlAgilityPack是在5年前,一些意外,让我从技术部门临时调到销售部门,负责建立一些流程和寻找潜在客户,最后在阿里巴巴找到了很多客户信息,非常全面,刚开始是手动复制到Excel, ...
- REGEX例子
作为REGEX的例子,代码9.3显示了一个给定的文件有多少行,具有给定的模式,通过命令行输入(注:有更有效率的方式来实现这个功能,如Unix下的grep命令,在这里只是给出了另一种方式).这个程序像下 ...
- CSharpGL(25)一个用raycast实现体渲染VolumeRender的例子
CSharpGL(25)一个用raycast实现体渲染VolumeRender的例子 本文涉及的VolumeRendering相关的C#代码是从(https://github.com/toolchai ...
- 简单例子了解View的事件分发
什么是事件分发 我们在写自定义ViewGroup或者自定义View的时候经常要处理用户的点击事件,如果我们的View在最底层,他在很多ViewGroup里面,我们如何让我们的点击事件准确传递到View ...
- 简单的例子了解自定义ViewGroup(一)
在Android中,控件可以分为ViewGroup控件与View控件.自定义View控件,我之前的文章已经说过.这次我们主要说一下自定义ViewGroup控件.ViewGroup是作为父控件可以包含多 ...
- kqueue例子
网络服务器通常都使用epoll进行异步IO处理,而开发者通常使用mac,为了方便开发,我把自己的handy库移植到了mac平台上.移植过程中,网上居然没有搜到kqueue的使用例子,让我惊讶不已.为了 ...
- 今天有群友不是很清楚htm直接存数据库的危害,我简单举个例子
通过这个案例就知道为什么不要把原生的html放数据库了 常见的几种转码 常用的几种显示方法 只有原生html和最下面一种弹框了,变成了持久xss 如果是Ajax的方式,请用@Ajax.JavaS ...
- ElasticSearch 5学习(5)——第一个例子(很实用)
想要知道ElasticSearch是如何使用的,最快的方式就是通过一个简单的例子,第一个例子将会包括基本概念如索引.搜索.和聚合等,需求是关于公司管理员工的一些业务. 员工文档索引 业务首先需要存储员 ...
- 以实际的WebGIS例子探讨Nginx的简单配置
文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/ 1.背景 以实际项目中的一个例子来详细讲解Nginx中的一般配置,其中涉 ...
随机推荐
- noip第28课作业
分段数列 [问题描述] 对于给定的一个长度为N的正整数数列A[i],现要将其分成连续的若干段,并且每段和不超过M(可以等于M),问最少能将其分成多少段使得满足要求. 输入格式: 输入第1行包含两个正整 ...
- VS SVN
AnkhSVN - Subversion Support for Visual Studio 直接包管理中就可以安装 VS2015和SVN合作 Visual Studio 添加SVN插件 Ank ...
- 杭电2133What day is it
给你个日期 问是星期几 知道1 1 1是周1就行了 #include <iostream>#include <cstdio>using namespace std ...
- ACE Editor在线代码编辑器简介及使用引导
转自博客:https://www.cnblogs.com/cz-xjw/p/6476179.html ACE 是一个开源的.独立的.基于浏览器的代码编辑器,可以嵌入到任何web页面或JavaScrip ...
- DOS和批处理基本命令
http://www.cnblogs.com/leizhao/archive/2013/03/07/2949026.html 1.rem和:: rem注释命令,该命令后的内容不被执行,但能回显 ::注 ...
- MySQL5.7Gtid主从复制总是遇到日志被清等出现无法正常主从复制
最近最是在MySQL5.7上的的gtid主从复制问题总是遇上下面问题: Last_Error: Coordinator stopped because there were error(s) in t ...
- js获取select标签选中的值及文本
原生js方式: var obj = document.getElementByIdx_x(”testSelect”); //定位id var index = obj.selectedIndex; // ...
- 全球第一开源ERP Odoo操作手册 数据库简介
1.3 数据库简介 每一个独立核算的企业都有一套相互关联的账簿体系, 把这一套完整的账簿体系建立在计算机系统中就称为一个数据库. 一般一个企业只用一个数据库. 如果企业有几个下属的独立核算的实体,也可 ...
- dapper视频
dapper是dotnet下的一种小巧快捷的ORM框架,本视频主要讲解了dapper的多库使用,以及常见的操作,如:对象查询.多集合查询,关联查询等,添加.修改.删除等. 视频地址:https://w ...
- JQuery的页面操作
window.location = "http://www.xxxxxxxx.net" 跳转后有后退功能 其实应该是 window.location.hrefwindow.loca ...