惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

罗磊的独立博客
SecWiki News
SecWiki News
酷 壳 – CoolShell
酷 壳 – CoolShell
爱范儿
爱范儿
量子位
M
MIT News - Artificial intelligence
GbyAI
GbyAI
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
TaoSecurity Blog
TaoSecurity Blog
博客园 - 【当耐特】
H
Heimdal Security Blog
腾讯CDC
The Last Watchdog
The Last Watchdog
Security Archives - TechRepublic
Security Archives - TechRepublic
Hacker News: Ask HN
Hacker News: Ask HN
S
Schneier on Security
Microsoft Security Blog
Microsoft Security Blog
WordPress大学
WordPress大学
博客园 - 司徒正美
Recent Commits to openclaw:main
Recent Commits to openclaw:main
C
Cybersecurity and Infrastructure Security Agency CISA
S
SegmentFault 最新的问题
大猫的无限游戏
大猫的无限游戏
Application and Cybersecurity Blog
Application and Cybersecurity Blog
F
Full Disclosure
有赞技术团队
有赞技术团队
T
Tailwind CSS Blog
Engineering at Meta
Engineering at Meta
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
T
Threatpost
月光博客
月光博客
A
Arctic Wolf
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
雷峰网
雷峰网
T
Troy Hunt's Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
The Cloudflare Blog
D
DataBreaches.Net
O
OpenAI News
L
LINUX DO - 最新话题
宝玉的分享
宝玉的分享
小众软件
小众软件
V
Vulnerabilities – Threatpost
A
About on SuperTechFans
人人都是产品经理
人人都是产品经理
T
The Exploit Database - CXSecurity.com
Martin Fowler
Martin Fowler
美团技术团队
P
Privacy International News Feed

博客园 - 00654

阳光已经好久不见 我这里有漂亮的繁体字,非主流图片 编写第一个JavaScript程序 - 00654 - 博客园 sql语句实现模糊搜索 反回上一页并刷新! - 00654 - 博客园 自己写的一个分页代码。写得不好哈! 取得页面执行时间的代码 - 00654 - 博客园 Java脚本提示用户是否确定操作。否则取消当前操作。 - 00654 - 博客园 checkbox控件.全选与不全选的切换 - 00654 - 博客园 用JavaScript判断用户输入的数据是否如何要求! - 00654 - 博客园 用Forms做管理员登陆。。。 [asp.net]Forms验证初步 SQL SERVER 函数 Scott Mitchell的ASP.NET2.0数据指南中文版索引 (好教程) Asp.Net 函数,方法。不断添加中。。 ASP.Net中控件的EnableViewState属性 ObjectDataSource控件的使用... Sql存储过程和函数集合.(不断更新中....) Select嵌套查询.(子查询取得其他表字段的值.并显示在本次查询的结果)
DateReader,DateAdapter,DateSet和SqlCommand的基本使用方法
00654 · 2006-12-02 · via 博客园 - 00654

 1using System;
 2using System.Data;
 3using System.Data.SqlClient;
 4
 5namespace Demo3
 6{
 7 /// <summary>
 8 /// Class1 的摘要说明。
 9 /// </summary>

10 class Class1
11 {
12  /// <summary>
13  /// 应用程序的主入口点。
14  /// </summary>

15  [STAThread]
16  static void Main(string[] args)
17  {
18   //
19   // TODO: 在此处添加代码以启动应用程序
20   Demo dm = new Demo();
21   dm.DoDemo();
22   //
23  }

24 }

25 class Demo
26 {
27  public void DoDemo()
28  {
29   DataSet ds = new DataSet(); //查一个名为d*的数据集。。
30   **ecuteOptions oExecute = new ExecuteOptions();
31   ds = oExecute.ExecuteandFill(); //掉用方法..得到返回的数据..(DataSet和SqlDataAdapter的使用)
32
33   oExecute.ExecuteNonQuery(); //返回受影响的行数.(.只执行`不返回.)
34
35   oExecute.ExecuteReader();
36   
37
38   int nSum=oExecute.ExecuteScalar();//反回结果集的第一行的第一列
39   Console.WriteLine("Record count is " +nSum.ToString());
40   
41  }

42 }

43 clas* **ecuteOptions
44 {
45  public SqlDataReader ExecuteReader()
46  {
47                        //建立一个连接池.SQL数据库..Windows身份验证模式
48   SqlConnection con = new SqlConnection("Server=localhost; Integrated Security=SSPI; database=mydatabase; Max Pool Size=75; Min Pool Size=5");
49                        //创建一个SqlCommand对象.并写入sql语句..使用SqlCommand可以直接对数据源进行操作..
50   SqlCommand cmdTitle = new SqlCommand("select Username,password,score from scoretable",con);
51                        //设置SQL执行类型为SQL文本模式..
52   cmdTitle.CommandType=CommandType.Text;
53   con.Open();//打开
54   SqlDataReader dr; //创建一个DataReader对象.(如果数据太大.内存中放不下.或则不需要修改数据.只向前读取数据.那么就可以使用DataReader)
55   dr =cmdTitle.ExecuteReader(CommandBehavior.CloseConnection);
56   return dr;
57  }

58  public int ExecuteScalar()
59  {
60                        //建立一个连接池.SQL数据库..Windows身份验证模式
61   SqlConnection con = new SqlConnection("Server=localhost; Integrated Security=SSPI; database=mydatabase;Max Pool Size=75; Min Pool Size=5");
62                        //创建一个SqlCommand对象.并写入sql语句..使用SqlCommand可以直接对数据源进行操作..
63   SqlCommand cmdTitleCount = new SqlCommand("select count(*) from scoretable",con); 
64                        //设置SQL执行类型为SQL文本模式..
65   cmdTitleCount.CommandType=CommandType.Text;
66   con.Open();//打开
67                        //cExecuteScalar() 一般用于有返回记录!
68   return Convert.ToInt32(cmdTitleCount.ExecuteScalar().ToString());  
69  }

70  public void ExecuteNonQuery()
71  {
72                        //建立一个连接池.SQL数据库..Windows身份验证模式
73   SqlConnection con = new SqlConnection("Server=localhost; Integrated Security=SSPI; database=mydatabase;Max Pool Size=75; Min Pool Size=5");
74                        //创建一个SqlCommand对象.并写入sql语句.. 使用SqlCommand可以直接对数据源进行操作..
75   SqlCommand cmdUpdateSales = new SqlCommand("Update scoretable set score = score+200 where username='成龙'",con);
76                        //设置SQL执行类型为SQL文本模式..
77   cmdUpdateSales.CommandType=CommandType.Text;
78   con.Open();//打开
79                        //ExecuteNonQuery()一般用于无返回记录!
80   cmdUpdateSale*.**ecuteNonQuery();//一般into delete update 都使用ExecuteNonQuery执行方式..
81  }

82  public DataSet ExecuteandFill()  //创建一个方法..返回类型为DataSet
83  {
84                        //建立一个连接池.SQL数据库..Windows身份验证模式
85   SqlConnection con = new SqlConnection("Server=localhost; Integrated Security=SSPI; database=mydatabase;Max Pool Size=75; Min Pool Size=5");
86                        //创建一个数据适配器(读取数据库记录..)使用SqlDataAdapter读取数据`然后把数据交给DataSet(也就是把数据放在内存中)由DataSet对内存中的数据进行操作. 
87   SqlDataAdapter da = new SqlDataAdapter("select username, password,score from scoretable",con);
88                        //创建一个数据集
89   DataSet ds = new DataSet();
90   con.Open();//打开
91   da.Fill(ds);//进行填充..
92   return ds;//返回ds的数据
93  }

94 }

95
96
97}