OracleDataAdapter.InsertCommand Proprietà

Definizione

Ottiene o imposta un'istruzione SQL o una stored procedure utilizzata per inserire nuovi record nel database.

public:
 property System::Data::OracleClient::OracleCommand ^ InsertCommand { System::Data::OracleClient::OracleCommand ^ get(); void set(System::Data::OracleClient::OracleCommand ^ value); };
public System.Data.OracleClient.OracleCommand InsertCommand { get; set; }
member this.InsertCommand : System.Data.OracleClient.OracleCommand with get, set
Public Property InsertCommand As OracleCommand

Valore della proprietà

Oggetto OracleCommand utilizzato durante un'operazione di aggiornamento per inserire i record nel database che corrispondono alle righe nuove nell'oggetto DataSet.

Esempio

Nell'esempio seguente viene creato un oggetto OracleDataAdapter e vengono impostate le SelectCommand proprietà e InsertCommand . Presuppone che sia già stato creato un OracleConnection oggetto.

Public Shared Function CreateCustomerAdapter(conn As OracleConnection) As OracleDataAdapter   

  Dim da As OracleDataAdapter = New OracleDataAdapter()  
  Dim cmd As OracleCommand  

  ' Create the SelectCommand.  

  cmd = New OracleCommand("SELECT * FROM Dept " & _  
                       "WHERE DName = :pDName AND Loc = :pLoc", conn)  

  cmd.Parameters.Add("pDName", OracleType.NVarChar, 14)  
  cmd.Parameters.Add("pLoc", OracleType.NVarChar, 13)  

  da.SelectCommand = cmd  

  ' Create the InsertCommand.  

  cmd = New OracleCommand("INSERT INTO Dept (DeptNo, DName) " & _  
                       "VALUES (:pDeptNo, :pDName)", conn)  

  cmd.Parameters.Add("pDeptNo", OracleType.Number, 2, "DeptNo")  
  cmd.Parameters.Add("pDName", OracleType.NVarChar, 14, "DName")  

  da.InsertCommand = cmd  

  Return da  
End Function  
public static OracleDataAdapter CreateCustomerAdapter(OracleConnection conn)  
{  
  OracleDataAdapter da = new OracleDataAdapter();  
  OracleCommand cmd;  

  // Create the SelectCommand.  

  cmd = new OracleCommand("SELECT * FROM Dept " +  
                       "WHERE DName = :pDName AND Loc = :pLoc", conn);  

  cmd.Parameters.Add("pDName", OracleType.NVarChar, 14);  
  cmd.Parameters.Add("pLoc", OracleType.NVarChar, 13);  

  da.SelectCommand = cmd;  

  // Create the InsertCommand.  

  cmd = new OracleCommand("INSERT INTO Dept (DeptNo, DName) " +  
                       "VALUES (:pDeptNo, :pDName)", conn);  

  cmd.Parameters.Add("pDeptNo", OracleType.Number, 2, "DeptNo");  
  cmd.Parameters.Add("pDName", OracleType.NVarChar, 14, "DName");  

  da.InsertCommand = cmd;  

  return da;  
}  

Commenti

Quando la proprietà viene assegnata a un oggetto creato OracleCommand in precedenza, l'oggetto InsertCommandOracleCommand non viene clonato. Mantiene invece InsertCommand un riferimento all'oggetto creato OracleCommandin precedenza.

Durante un'operazione di aggiornamento, se InsertCommand non è impostata e le informazioni sulla chiave primaria sono presenti in DataSet, è possibile usare la OracleCommandBuilder classe per generare InsertCommandautomaticamente e comandi aggiuntivi necessari per riconciliare il DataSet database. A tale scopo, impostare la SelectCommand proprietà dell'oggetto OracleDataAdapter. La logica di generazione richiede inoltre che le informazioni sulla colonna chiave siano presenti in DataSet. Per altre informazioni, vedere Generazione di comandi con CommandBuilders.

Nota

Se l'esecuzione di questo comando restituisce righe, queste righe possono essere aggiunte all'oggetto DataSet a seconda della modalità di impostazione UpdatedRowSource della proprietà dell'oggetto OracleCommand .

Quando si aggiorna una colonna con il LONG RAW tipo di dati, viene generata un'eccezione quando si immette un valore di NULL nella colonna. Il tipo di dati Oracle LONG RAW è un tipo deprecato in Oracle versione 8.0. Per evitare questo errore, usare il BLOB tipo di LONG RAWdati anziché .

Si applica a

Vedi anche