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的更多相关文章

  1. SQLServer地址搜索性能优化例子

    这是一个很久以前的例子,现在在整理资料时无意发现,就拿出来再改写分享. 1.需求 1.1 基本需求: 根据输入的地址关键字,搜索出完整的地址路径,耗时要控制在几十毫秒内. 1.2 数据库地址表结构和数 ...

  2. C#+HtmlAgilityPack+XPath带你采集数据(以采集天气数据为例子)

    第一次接触HtmlAgilityPack是在5年前,一些意外,让我从技术部门临时调到销售部门,负责建立一些流程和寻找潜在客户,最后在阿里巴巴找到了很多客户信息,非常全面,刚开始是手动复制到Excel, ...

  3. REGEX例子

    作为REGEX的例子,代码9.3显示了一个给定的文件有多少行,具有给定的模式,通过命令行输入(注:有更有效率的方式来实现这个功能,如Unix下的grep命令,在这里只是给出了另一种方式).这个程序像下 ...

  4. CSharpGL(25)一个用raycast实现体渲染VolumeRender的例子

    CSharpGL(25)一个用raycast实现体渲染VolumeRender的例子 本文涉及的VolumeRendering相关的C#代码是从(https://github.com/toolchai ...

  5. 简单例子了解View的事件分发

    什么是事件分发 我们在写自定义ViewGroup或者自定义View的时候经常要处理用户的点击事件,如果我们的View在最底层,他在很多ViewGroup里面,我们如何让我们的点击事件准确传递到View ...

  6. 简单的例子了解自定义ViewGroup(一)

    在Android中,控件可以分为ViewGroup控件与View控件.自定义View控件,我之前的文章已经说过.这次我们主要说一下自定义ViewGroup控件.ViewGroup是作为父控件可以包含多 ...

  7. kqueue例子

    网络服务器通常都使用epoll进行异步IO处理,而开发者通常使用mac,为了方便开发,我把自己的handy库移植到了mac平台上.移植过程中,网上居然没有搜到kqueue的使用例子,让我惊讶不已.为了 ...

  8. 今天有群友不是很清楚htm直接存数据库的危害,我简单举个例子

     通过这个案例就知道为什么不要把原生的html放数据库了  常见的几种转码  常用的几种显示方法 只有原生html和最下面一种弹框了,变成了持久xss 如果是Ajax的方式,请用@Ajax.JavaS ...

  9. ElasticSearch 5学习(5)——第一个例子(很实用)

    想要知道ElasticSearch是如何使用的,最快的方式就是通过一个简单的例子,第一个例子将会包括基本概念如索引.搜索.和聚合等,需求是关于公司管理员工的一些业务. 员工文档索引 业务首先需要存储员 ...

  10. 以实际的WebGIS例子探讨Nginx的简单配置

    文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/ 1.背景 以实际项目中的一个例子来详细讲解Nginx中的一般配置,其中涉 ...

随机推荐

  1. 木马入侵查杀 linux

     目 录: 一.问题现象: 二.问题排查: 1.netstat 排查: 2.top查看: 3.lsof -c 命令排查: 4.确定中木马了. 三.木马查杀: 木马1,清除: 木马2,清除: 四.后续处 ...

  2. 火狐浏览器(Firefox)打开EBS form的设置方法

    http://yedward.net/?id=247 客户在使用EBS的时候,很多都是使用IE浏览器打开,但是EBS并不仅仅只是支持IE,对于谷歌浏览器(Chrome).火狐浏览器(Firefox)也 ...

  3. mssql中按周进行表分区的方法

    创建一个包含了一个持久化计算列的表,类似于下面.然后以这个列作为分区的依据. CREATE TABLE [dbo].[test] ( ) NOT NULL , [time] [DATETIME] NU ...

  4. [转载]DevOps建立全生命周期管理

    全生命周期管理(ALM)领域作为企业DevOps实践的总体支撑,应该说是DevOps领域中最为重要的实践领域,也是所有其他实践的基础设施.现在很多企业都非常重视CI/CD自动化工具的引入和推广,但是对 ...

  5. python操作excel及json

    有一个存着学生成绩的文件:stuscore.txt,里面存的是json串,json串读起来特别不直观,需要你写代码把它都写到excel中,并计算出总分和平均分,json格式如下: { ":[ ...

  6. 【转】C# Enum,Int,String的互相转换 枚举转换

    Enum为枚举提供基类,其基础类型可以是除 Char 外的任何整型.如果没有显式声明基础类型,则使用 Int32.编程语言通常提供语法来声明由一组已命名的常数和它们的值组成的枚举. 注意:枚举类型的基 ...

  7. “全栈2019”Java多线程第三十一章:中断正在等待显式锁的线程

    难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java多 ...

  8. Python2.7更新pip:UnicodeDecodeError: 'ascii' codec can't decode byte 0xb7 in position 7: ordinal not in range(128)

    1.首先更新pip版本的时候出现.这是出现在python2.7.16出现的问题 2.进入你的pyhton目录下的Lib\mimetypes.py 打开它 3.在import下面加入这代码 if sys ...

  9. [学习笔记]min_25筛

    神佬yyb 神佬zsy 想不到花了两个小时的时间看 \(min\_25\) 筛就看懂了 实际去追了一下魔禁3 我们先举个例子.如求 \[\sum_{i=1}^{n}f(i)\] 其中 \(f(i)\) ...

  10. skynet 源码阅读笔记 bootstrap.lua

    最近几周粗略看了 skynet 代码的 C 部分.遇到很多知识点以前只是知道,但并不十分了解,所以这是一个学习的过程. 从 main 函数开始,闷头一阵看下来,着实蛋疼. 当看了 skynet_mq. ...