2010年12月7日 星期二

ADO.net基于SQL是实现模式

using System.Data;
using System.Data.SqlClient;
using System;

class test
{
private static void Main()
{
//建立数据源
SqlConnection con = new SqlConnection();
con.ConnectionString ="Data Source=PC-200809131136;Initial Catalog=Northwind;Integrated Security=True";
con.Open();

//链接数据库
SqlCommand sc = new SqlCommand();
sc.Connection = con;
sc.CommandType = CommandType.Text;

sc.CommandText = "select * from Customers where CustomerID='BLAUS' ";

SqlDataReader reader =sc.ExecuteReader ();

//输入结果
while (reader .Read ())
{
Console.WriteLine("\t{0},\t{1},\t{2}",reader[0],reader[1],reader[2]);
}
Console.ReadLine();

}
}

沒有留言:

張貼留言