OracleDataAdapter::SelectCommand Property
.NET Framework (current version)
Gets or sets an SQL statement or stored procedure used to select records in the database.
Assembly: System.Data.OracleClient (in System.Data.OracleClient.dll)
public: property OracleCommand^ SelectCommand { OracleCommand^ get(); void set(OracleCommand^ value); }
Property Value
Type: System.Data.OracleClient::OracleCommand^An OracleCommand that is used during a fill operation to select records from database for placement in the DataSet.
When SelectCommand is assigned to a previously created OracleCommand, the OracleCommand is not cloned. Instead, the SelectCommand maintains a reference to the previously created OracleCommand object.
If SelectCommand does not return any rows, no tables are added to the DataSet, and no exception is raised.
The following example creates an OracleDataAdapter and sets the SelectCommand and InsertCommand properties. It assumes you have already created an OracleConnection object.
[Visual Basic]
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
[C#]
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;
}
.NET Framework
Available since 1.1
Available since 1.1
Show: