Represents an open connection to SugarCRM.
The following example creates a
SugarCommand and a
SugarConnection. The
SugarConnection 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 sugarConnectionString)
{
// If the connection string is empty, use default.
if(sugarConnectionString == "")
{
sugarConnectionString =
"server=https://your_company.sugaropencloud.eu;user id=admin;password=AmFFA4ZryM;";
}
SugarConnection myConn = new SugarConnection(sugarConnectionString);
string myInsertQuery = "INSERT INTO Campaigns (name, campaign_type, end_date, status) VALUES ('Sale campaign', 'Email', '2016-12-12', 'Active')";
SugarCommand sugarCommand = new SugarCommand(myInsertQuery);
sugarCommand.Connection = myConn;
myConn.Open();
try
{
sugarCommand.ExecuteNonQuery();
}
finally
{
myConn.Close();
}
}
Public Sub InsertRow(sugarConnectionString As String)
' If the connection string is empty, use default.
If sugarConnectionString = "" Then
sugarConnectionString = _
"server=https://your_company.sugaropencloud.eu;user id=admin;password=AmFFA4ZryM;"
End If
Dim myConn As New SugarConnection(sugarConnectionString)
Dim myInsertQuery As String = "INSERT INTO Campaigns (name, campaign_type, end_date, status) VALUES ('Sale campaign', 'Email', '2016-12-12', 'Active')"
Dim sugarCommand As New SugarCommand(myInsertQuery)
sugarCommand.Connection = myConn
myConn.Open()
Try
sugarCommand.ExecuteNonQuery()
Finally
myConn.Close()
End Try
End Sub