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中的一般配置,其中涉 ...
随机推荐
- POJ3616--Milking Time(动态规划)
Bessie is such a hard-working cow. In fact, she is so focused on maximizing her productivity that sh ...
- DXP中插入LOGO字体方法(2)
利用字体制作软件font creator program 4.1 1.文件-->新建 2.右键---->属性 3.去掉黑框和黑底,删除即可! 4.选 工具--->导入图像,载入字体图 ...
- I - Dividing Stones
Description There are N stones, which can be divided into some piles arbitrarily. Let the value of e ...
- hdu 1.2.7
#include<cstdio> #include<iostream> using namespace std; int main() { //freopen("in ...
- 如何利用JUnit开展一个简单的单元测试(测试控制台输出是否正确)
待测类(CreateString)如下: public class CreateString { public void createString() { //Output the following ...
- VS2010的快捷键乱
vs2010的快捷键乱了,点击回车会出现属性窗口,点击退格键会相当于编辑里面的撤销功能 点击ctrl+s会出现sharepoint窗口,在网上找了一个解决方式(很难找),原问在这: http://q. ...
- WPF实战案例-数据代理
在我们wpf开发中,很多人会有mvvm模式去做wpf的项目. 是否有人遇到这样一个场景:在一个界面上,有个tabcontrol上面有4个页签,每个页签里面都有一个datagrid,里面显示的列基本一样 ...
- [leetcode.com]算法题目 - Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For e ...
- UVA10829 L-Gap Substrings(后缀数组+ST表)
后缀数组+ST表. 代填的坑. \(Code\ Below:\) #include <bits/stdc++.h> #define ll long long using namespace ...
- Swift5 语言指南(二十五) 自动引用计数(ARC)
Swift使用自动引用计数(ARC)来跟踪和管理应用程序的内存使用情况.在大多数情况下,这意味着内存管理在Swift中“正常工作”,您不需要自己考虑内存管理.当不再需要这些实例时,ARC会自动释放类实 ...