2015-10-01 49 views
0

,我嘗試插入並使用以下行更新表:甲骨文,插入的行數/ C#中更新

OracleDataAdapter da = new OracleDataAdapter(query, connection); 
da.Fill(ds); 

這工作。

但是,我需要知道如何獲取更新插入的行數。查詢是一樣的東西

insert into someTable Values(...) 
+0

您正在獲取數據集? –

+0

是ds是一個數據集 – user2482541

+0

然後你有沒有嘗試做ds.Tables [0] .Rows.Count? –

回答

0

沒有辦法知道記錄集計數不運行單獨的COUNT(*)查詢。這是設計。 DataReader和DataAdapter是隻讀的,只讀。

您可以嘗試下面的替代方法來獲取受影響的行。

public bool UploadBulkData(List<CustomerDTO> bulkData) 
    { 
     bool returnValue = false; 
     try 
     { 

      string query = @"insert into PCMS.Customer (surname, firstName, emailAddress) values 
          (:surname, :firstName, :emailAddress)"; 
      oracleConnection.Open(); 
      using (var command = oracleConnection.CreateCommand()) 
      { 
       command.CommandText = query; 
       command.CommandType = CommandType.Text; 
       command.BindByName = true; 
       // In order to use ArrayBinding, the ArrayBindCount property 
       // of OracleCommand object must be set to the number of records to be inserted 
       command.ArrayBindCount = bulkData.Count; 
       command.Parameters.Add(":surname", OracleDbType.Varchar2, bulkData.Select(c => c.Surname).ToArray(), ParameterDirection.Input); 
       command.Parameters.Add(":firstName", OracleDbType.Varchar2, bulkData.Select(c => c.FirstName).ToArray(), ParameterDirection.Input); 
       command.Parameters.Add(":emailAddress", OracleDbType.Varchar2, bulkData.Select(c => c.EmailAddress).ToArray(), ParameterDirection.Input); 
       int result = command.ExecuteNonQuery(); 
       **result is what you need** 
      } 

     } 
     catch (OracleException ex) 
     { 
      //Log error thrown 
     } 
     finally 
     { 
      oracleConnection.Close(); 
     } 
     return returnValue; 
    }