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中的一般配置,其中涉 ...
随机推荐
- 1、从C语言到C++
1.面向对象的C++ c++是在C语言的基础上发展起来的一门语言,C++是即支持结构化程序编程又支持面向对象程序设计的混合型语言.他一方面提供了对C的兼容性,保持了C的简介.高效,接近汇编语言的特点, ...
- bootstrap3相关文档
,每列分配多列 <divclass="container"> <div class="row"> <div class=" ...
- AngularJS 单元测试 Karma jasmine
当AngularJS项目越来越大时候,需要进行单元测试,可以先开发功能再进行测试,也可以先进行测试. 一.karma 是一个基于Node.js(先要安装)的JavaScript测试执行过程管理工具( ...
- 笑话库存加网址http://www.jokeji.cn/list18_11.htm
19.富二代王晓伟成绩很差,老爸想给他找个家教老爸:“儿子,想找什么样的家教啊?”儿子:“要漂亮的,女的,衣服不能太保守,花样要多!”老爸:“儿子,你TM指的是岛国的苍老师吗?”@呦呦ta爹 20.哥 ...
- ASP.NET Core 2.1 源码学习之 Options[3]:IOptionsMonitor
前面我们讲到 IOptions 和 IOptionsSnapshot,他们两个最大的区别便是前者注册的是单例模式,后者注册的是 Scope 模式.而 IOptionsMonitor 则要求配置源必须是 ...
- [LintCode] Longest Increasing Continuous subsequence
http://www.lintcode.com/en/problem/longest-increasing-continuous-subsequence/# Give you an integer a ...
- Spring Security Hello World Example--reference
In this tutorial, we will see how we can use Spring security to protect specific resources. This Hel ...
- asp.net core 使用identityServer4的密码模式来进行身份认证(2) 认证授权原理
前言:本文将会结合asp.net core 认证源码来分析起认证的原理与流程.asp.net core版本2.2 对于大部分使用asp.net core开发的人来说. 下面这几行代码应该很熟悉了. s ...
- ssh远程登录出现Host key verification failed.解决办法
今天通过ssh和域名连接主机: IcarusdeMacBook-Pro:~ icarus$ ssh root@icarusyu.me 出现了如下错误: @@@@@@@@@@@@@@@@@@@@@@@@ ...
- Android--------------BroadcastReceiver的学习
一.广播的注册方式 发送广播: Intent mIntent = new Intent("com.simware.BroadcastReceiverDemo"); mIntent. ...