Represents an open connection to DB2.
The following example creates a
DB2Command and a
DB2Connection. The
DB2Connection 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 db2ConnectionString)
{
// If the connection string is empty, use default.
if(db2ConnectionString == "")
{
db2ConnectionString =
"user id=db2admin;server=db2;database=SAMPLE;";
}
DB2Connection myConn = new DB2Connection(db2ConnectionString);
string myInsertQuery = "INSERT INTO DEPT VALUES (50,'Development','Philadelphia')";
DB2Command db2Command = new DB2Command(myInsertQuery);
db2Command.Connection = myConn;
myConn.Open();
try
{
db2Command.ExecuteNonQuery();
}
finally
{
myConn.Close();
}
}
Public Sub InsertRow(db2ConnectionString As String)
' If the connection string is empty, use default.
If db2ConnectionString = "" Then
db2ConnectionString = _
"user id=db2admin;server=db2;database=SAMPLE;"
End If
Dim myConn As New DB2Connection(db2ConnectionString)
Dim myInsertQuery As String = "INSERT INTO DEPT VALUES (50,'Development','Philadelphia')"
Dim db2Command As New DB2Command(myInsertQuery)
db2Command.Connection = myConn
myConn.Open()
Try
db2Command.ExecuteNonQuery()
Finally
myConn.Close()
End Try
End Sub
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2