Represents an open connection to Dynamics 365.
The following example creates a
DynamicsCommand and a
DynamicsConnection. The
DynamicsConnection 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 dynamicsConnectionString)
{
// If the connection string is empty, use default.
if(dynamicsConnectionString == "")
{
dynamicsConnectionString =
"Server=https://your_company.crm4.dynamics.com;User [email protected];Password=A123456789;";
}
DynamicsConnection myConn = new DynamicsConnection(dynamicsConnectionString);
string myInsertQuery = "INSERT INTO Contact (FirstName,LastName) VALUES ('John','Smith')";
DynamicsCommand dynamicsCommand = new DynamicsCommand(myInsertQuery);
dynamicsCommand.Connection = myConn;
myConn.Open();
try
{
dynamicsCommand.ExecuteNonQuery();
}
finally
{
myConn.Close();
}
} |
|
|---|
Public Sub InsertRow(dynamicsConnectionString As String)
' If the connection string is empty, use default.
If dynamicsConnectionString = "" Then
dynamicsConnectionString = _
"Server=https://your_company.crm4.dynamics.com;User [email protected];Password=A123456789;"
End If
Dim myConn As New DynamicsConnection(dynamicsConnectionString)
Dim myInsertQuery As String = "INSERT INTO Contact (FirstName,LastName) VALUES ('John','Smith')"
Dim dynamicsCommand As New DynamicsCommand(myInsertQuery)
dynamicsCommand.Connection = myConn
myConn.Open()
Try
dynamicsCommand.ExecuteNonQuery()
Finally
myConn.Close()
End Try
End Sub |