dreader.cs
资源名称:Visual.rar [点击查看]
上传用户:yiyuerguo
上传日期:2014-09-27
资源大小:3781k
文件大小:1k
源码类别:
C#编程
开发平台:
Others
- using System;
- using System.Data;
- using System.Data.SqlClient;
- namespace DataReader1App2
- {
- /// <summary>
- /// Class1 的摘要说明。
- /// </summary>
- class DataReader1
- {
- /// <summary>
- /// 应用程序的主入口点。
- /// </summary>
- [STAThread]
- static void Main(string[] args)
- {
- SqlConnection connection = new SqlConnection(@"Data Source=(local);Integrated Security=SSPI;"+
- "Initial Catalog = NorthWind");
- connection.Open();
- SqlCommand command = connection.CreateCommand();
- command.CommandText = "SELECT CategoryID, CategoryName from Categories";
- SqlDataReader reader = command.ExecuteReader();
- //使用DataReader遍历查询结果
- while(reader.Read())
- {
- Console.WriteLine("t{0}t{1}",reader["CategoryID"],reader["CategoryName"]);
- }
- reader.Close();
- connection.Close();
- Console.ReadLine();
- }
- }
- }