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

推荐订阅源

GbyAI
GbyAI
J
Java Code Geeks
雷峰网
雷峰网
WordPress大学
WordPress大学
宝玉的分享
宝玉的分享
云风的 BLOG
云风的 BLOG
V
Visual Studio Blog
V
Vulnerabilities – Threatpost
S
Securelist
The Hacker News
The Hacker News
The Register - Security
The Register - Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Help Net Security
Help Net Security
G
Google Developers Blog
Hugging Face - Blog
Hugging Face - Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
M
MIT News - Artificial intelligence
AI
AI
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
The GitHub Blog
The GitHub Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Schneier on Security
Schneier on Security
N
Netflix TechBlog - Medium
T
The Blog of Author Tim Ferriss
Google DeepMind News
Google DeepMind News
Hacker News - Newest:
Hacker News - Newest: "LLM"
H
Hacker News: Front Page
博客园 - 司徒正美
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
B
Blog
Microsoft Azure Blog
Microsoft Azure Blog
大猫的无限游戏
大猫的无限游戏
Security Latest
Security Latest
Engineering at Meta
Engineering at Meta
N
News and Events Feed by Topic
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
酷 壳 – CoolShell
酷 壳 – CoolShell
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
T
Threat Research - Cisco Blogs
U
Unit 42
V
V2EX
V2EX - 技术
V2EX - 技术
L
LINUX DO - 最新话题
aimingoo的专栏
aimingoo的专栏
Microsoft Security Blog
Microsoft Security Blog
Recorded Future
Recorded Future
P
Privacy & Cybersecurity Law Blog
美团技术团队
小众软件
小众软件
F
Fortinet All Blogs

博客园 - 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}