ConsoleApplication11
{
    class Program
    {
        
static void Main(string[] args)
        {
            SqlConnection conn 
= new SqlConnection("Server=zhuobin;uid=sa;pwd=zhuobin;database=northwind");
            
string sql = @"select contactname from customers";
            
try
            {
                conn.Open();
                
//create the command
                SqlCommand cmd = new SqlCommand(sql,conn);
                SqlDataReader reader 
= cmd.ExecuteReader();
                
while (reader.Read())
                {
                    Console.WriteLine(
"{0}",reader[0]);
                } reader.Close();

            }
            
catch (SqlException ex)
            {
                Console.WriteLine(
"The error:" + ex.Message);
            }
            
finally
            {
                conn.Close();
                Console.WriteLine(
"The end!");
            }
            Console.ReadLine();
            

        }
    }
}

相关文章:

  • 2021-12-14
  • 2021-06-30
  • 2022-12-23
  • 2021-06-28
  • 2021-08-05
  • 2021-11-20
猜你喜欢
  • 2021-10-21
  • 2022-12-23
  • 2021-12-09
  • 2022-12-23
  • 2021-12-21
  • 2022-12-23
  • 2021-06-20
相关资源
相似解决方案