2014-02-28 184 views

回答

1

你蜂房安裝ODBC驅動程序。並配置它。例如,在我的例子中,我將dsn名稱配置爲horton。這裏是代碼:

static DataTable GetDataFromHive() 
     { 
      OdbcConnection DbConnection = new OdbcConnection("DSN=horton"); 
      try 
      { 
       DbConnection.Open(); 
      } 
      catch (OdbcException ex) 
      { 
       Console.WriteLine(ex.Message); 
       return null; 
      } 
      OdbcCommand cmd = DbConnection.CreateCommand(); 
      cmd.CommandText = "SELECT * FROM sample_08 LIMIT 100;"; 
      DbDataReader dr = cmd.ExecuteReader(); 
      var dataTable = new DataTable(); 
      dataTable.Load(dr); 
      DbConnection.Close(); 
      return dataTable; 
     }