配色: 字号:
连接模式读
2013-01-06 | 阅:  转:  |  分享 
  
usingSystem;

usingSystem.Collections.Generic;

usingSystem.ComponentModel;

usingSystem.Data;



usingSystem.Linq;

usingSystem.Text;



usingSystem.Configuration;

usingSystem.Data.SqlClient;



namespaceReadByConnected

{

classProgram

{

staticvoidMain(string[]args)

{

using(SqlConnectionconn=newSqlConnection(ConfigurationManager.ConnectionStrings["SqlConn"].ConnectionString))

{

conn.Open();

using(SqlCommandcomm=newSqlCommand())

{

comm.CommandText="SelectFromStudent";

comm.Connection=conn;

SqlDataReaderread=comm.ExecuteReader();

while(read.Read())

{

Console.WriteLine(read.GetName(0)+":"+read[0]);

Console.WriteLine(read.GetName(1)+":"+read[1]);

Console.WriteLine(read.GetName(2)+":"+read[2]);

Console.WriteLine(read.GetName(3)+":"+read[3]);

Console.WriteLine(read.GetName(4)+":"+read[4]);

Console.WriteLine();

}

Console.ReadKey();

}

}

}

}

}

献花(0)
+1
(本文系巭奥特曼首藏)