【C#學習筆記】讀SQL Server2008

Dsp Tian發表於2017-08-27
using System;
using System.Data.SqlClient;

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            SqlConnection con = new SqlConnection("server=.\\sqlexpress;uid=sa;pwd=123456;database=stuDB");
            con.Open();

            SqlCommand com = con.CreateCommand();
            com.CommandText = "select * from stuInfo";

            SqlDataReader reader = com.ExecuteReader();

            while (reader.Read())
                Console.WriteLine(reader["stuName"].ToString() + reader["stuAge"].ToString() + reader["stuSex"].ToString());

            reader.Close();
            con.Close();
            Console.Read();
        }      
    }
}

 

相關文章