SqlDataReader读取数据
2008-11-21 15:22
405 查看
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; using System.Data.SqlClient; namespace ConsoleApplication11 { class Program { static void Main(string[] args) { SqlConnection conn = new SqlConnection("Server=zhuobin;uid=sa;pwd=zhuobin;database=northwind"); string sql = @"select contactname from customers"; try { conn.Open(); //create the command SqlCommand cmd = new SqlCommand(sql,conn); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { Console.WriteLine("{0}",reader[0]); } reader.Close(); } catch (SqlException ex) { Console.WriteLine("The error:" + ex.Message); } finally { conn.Close(); Console.WriteLine("The end!"); } Console.ReadLine(); } } }
相关文章推荐
- SqlDataReader读取分页数据,pageCount你是肿么了?
- 使用SqlDataReader读取数据示例
- 使用 SqlDataReader 读取数据示例
- SqlDataReader读取数据的代码
- 在循环中读取sqlDataReader.Read()中的所有列,数据类型如何转换?
- 第四课 使用SqlDataReader读取数据(翻译)
- 以SqlDataReader读取数据
- 使用 SqlDataReader 读取数据示例
- 读取SqlDataReader数据动态创建DataTable
- 当获取相似数据时,使用不同方法调用不同sp,但是使用同一个方法去用IIDataReader或者SqlDataReader读取数据时需要判断column name是否存在。
- SqlDataReader对数据的读取
- 数据库操作_连接SQL Server数据库示例;连接ACCESS数据库;连接到 Oracle 数据库示例;SqlCommand 执行SQL命令示例;SqlDataReader 读取数据示例;使用DataAdapter填充数据到DataSet;使用DataTable存储数据库表;将数据库数据填充到 XML 文件;10 使用带输入参数的存储过程;11 使用带输入、输出参数的存储过程示;12 获得数据库中表的数目和名称;13 保存图片到SQL Server数据库示例;14 获得插入记录标识号;Exce
- 利用SqlDataReader读取大量的数据库数据
- SqlDataReader读取数据
- JScript.Net之SqlDataReader读取数据
- SqlDataReader 与 DataSet读取sql中的数据
- Lesson 04: Reading Data with the SqlDataReader(使用SqlDataReader读取数据)
- JScript.Net 之 SqlDataReader读取数据
- SqlDataReader And SqlCommand读取数据
- 使用SqlDataReader读取数据示例