using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace A006
{
public class ExecuteNonQueryExample
{
public static void Main()
{
string str = "Data Source=(local);Initial Catalog=Student1;Integrated Security=True;Pooling=False";
SqlConnection conn = new SqlConnection(str);
string SQLstr = "select top 1 * from Table";
SqlCommand comm = new SqlCommand(SQLstr, conn);
SqlDataReader rd;
try
{
conn.Open();
rd = comm.ExecuteReader();
while (rd.Read())
{
Console.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}", rd["StudentID"].ToString(), rd["XueHao"], rd[2], rd[3], rd[4], rd[5]);
}
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
conn.Close();
}
}
}
}