⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 datareadersql.cs

📁 Professional C# 2nd Edition
💻 CS
字号:
using System;
using System.Data.SqlClient;

public class DataReaderSql
{
  public static int Main(string[] args)
  {
    string        source = Login.Connection ;

    string        select = "SELECT ContactName,CompanyName FROM Customers" ;

    SqlConnection conn = new SqlConnection ( source ) ;

    try
    {
      using ( conn )
      {
        conn.Open ( ) ;

        SqlCommand    cmd = new SqlCommand ( select , conn ) ;

        using ( SqlDataReader aReader = cmd.ExecuteReader ( ) )
        {
          while ( aReader.Read ( ) )
            Console.WriteLine ( "'{0}' from {1}" , aReader.GetString(0) , aReader.GetString ( 1 ) ) ;

          aReader.Close ( ) ;
        }

        conn.Close ( ) ;
      }
    }
    catch ( Exception e )
    {
      Console.WriteLine ( e ) ;
      Console.WriteLine ( ) ;
      Console.WriteLine ( "Chances are your database does not have a user" ) ;
      Console.WriteLine ( "called QSUser, or you do not have the NetSDK database installed." ) ;
    }

    return 0;
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -