62,046
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace DataReader
{
class Program
{
static void Main(string[] args)
{
SqlConnection thisConnection = new SqlConnection("persist security info=true;password=11;user id=ggg521;initial catalog=northwind;data source=127.0.0.1;");
thisConnection.Open();
SqlCommand thisCommand = new SqlCommand();
thisCommand.Connection = thisConnection;//加上这一句
thisCommand.CommandText = "select * from Customers";
SqlDataReader thisDataReader = thisCommand.ExecuteReader(); while (thisDataReader.Read())
{
Console.WriteLine("\t{0} \t{1}", thisDataReader[0], thisDataReader[1]);
}
thisDataReader.Close();
thisConnection.Close();
Console.ReadKey();
}
}
}
SqlConnection thisConnection = new SqlConnection("persist security info=true;password=11;user id=ggg521;initial catalog=northwind;data source=127.0.0.1;");
thisConnection.Open();
SqlCommand thisCommand = new SqlCommand("select * from Customers",thisConnection);//最简单的写法
SqlDataReader thisDataReader = thisCommand.ExecuteReader(); while (thisDataReader.Read())
{
Console.WriteLine("\t{0} \t{1}", thisDataReader[0], thisDataReader[1]);
}
thisDataReader.Close();
thisConnection.Close();
Console.ReadKey();