Represents an open connection to Oracle.
The following example creates a
OracleCommand and a
OracleConnection. The
OracleConnection is opened and set as the
Connection property. The example then calls
ExecuteNonQuery method, and closes the connection. To accomplish this, the
ExecuteNonQuery is passed a connection string and a query string that is SQL INSERT statement.
|
|---|
public void InsertRow(string oracleConnectionString)
{
// If the connection string is empty, use default.
if(oracleConnectionString == "")
{
oracleConnectionString =
"User Id=Scott;Password=tiger;Data Source=Ora;";
}
OracleConnection myConn = new OracleConnection(oracleConnectionString);
string myInsertQuery = "INSERT INTO DEPT VALUES (50,'Development','Philadelphia')";
OracleCommand oracleCommand = new OracleCommand(myInsertQuery);
oracleCommand.Connection = myConn;
myConn.Open();
try
{
oracleCommand.ExecuteNonQuery();
}
finally
{
myConn.Close();
}
} |
|
|---|
Public Sub InsertRow(oracleConnectionString As String)
' If the connection string is empty, use default.
If oracleConnectionString = "" Then
oracleConnectionString = _
"User Id=Scott;Password=tiger;Data Source=Ora;"
End If
Dim myConn As New OracleConnection(oracleConnectionString)
Dim myInsertQuery As String = "INSERT INTO DEPT VALUES (50,'Development','Philadelphia')"
Dim oracleCommand As New OracleCommand(myInsertQuery)
oracleCommand.Connection = myConn
myConn.Open()
Try
oracleCommand.ExecuteNonQuery()
Finally
myConn.Close()
End Try
End Sub |