2012年7月18日

数据读取器---获取数据的信息

摘要: 实例:使用数据读取器获取结果集的信息using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Data;using System.Data.SqlClient;namespace ResultSetInfo{ class Program { static void Main(string[] args) { string connString = @"Data Source=SNH;Initial Ca... 阅读全文

posted @ 2012-07-18 17:35 流星落 阅读(280) 评论(0) 推荐(0) 编辑

数据读取器---使用列名索引器

摘要: using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Data;using System.Data.SqlClient;namespace OrdinelIndexer{ class Program { static void Main(string[] args) { string connString = @"server=.;integrated security =true;database... 阅读全文

posted @ 2012-07-18 15:39 流星落 阅读(186) 评论(0) 推荐(0) 编辑

数据读取器---使用序数索引器

摘要: using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Data;using System.Data.SqlClient;namespace OrdinelIndexer{ class Program { static void Main(string[] args) { string connString = @"server=.;integrated security =true;database... 阅读全文

posted @ 2012-07-18 15:27 流星落 阅读(159) 评论(0) 推荐(0) 编辑

数据读取器概述

摘要: 数据读取器是实现了System.Data.IDataReader接口的对象,它是快速的、未缓存的、仅向前的、只读的、已连接数据源的、逐行检索数据的数据流。它在遍历结果集时,一次只能读取一行。数据读取器不能直接实例化,而要通过执行命令对象的ExecuteReader方法创建它的实例。如下创建SqlClient数据读取器:SqlDataReader rdr=cmd.ExecuteReader();该数据读取器可用来访问查询的结果集。实例:遍历结果集using System;using System.Collections.Generic;using System.Linq;using Syste. 阅读全文

posted @ 2012-07-18 14:07 流星落 阅读(324) 评论(0) 推荐(0) 编辑

命令对象SqlCommand(五)命令参数

摘要: 向某个表中插入新行时,有两种方式,一种是相对低效的方式是动态构建SQL语句,也就是生成包含CommandText属性中所有必要信息的字符串。这不是推荐的最佳做法,有SQL注入攻击的风险。更好的方法是使用命令参数的做法,命令参数在命令文本中是点位符,标记出将被替代的值的位置。在SQL Server中使用命名参数(named parameters),这些参数以@符号开始,后跟不带空格的参数名。如:INSERT INTO MyTable VALUES(@MyName,@MyNumber)使用命令参数实例:using System;using System.Collections.Generic;us 阅读全文

posted @ 2012-07-18 12:52 流星落 阅读(503) 评论(0) 推荐(0) 编辑

命令对象SqlCommand(四)执行语句

摘要: View Code using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Data.SqlClient;namespace CommandNonQuery{ class Program { static void Main(string[] args) { SqlConnection conn = new SqlConnection(@"Data Source=.;Initial Catalog=N... 阅读全文

posted @ 2012-07-18 00:46 流星落 阅读(306) 评论(0) 推荐(0) 编辑

导航