dotConnect for SugarCRM Documentation
Devart.Data.Sugar Namespace / SugarConnection Class / CreateCommand Method
Example

CreateCommand Method (SugarConnection)
Creates and returns a SugarCommand object associated with the SugarConnection.
Creates and returns a SugarCommand object associated with the SugarConnection.
Syntax
'Declaration
 
Public Shadows Function CreateCommand() As SugarCommand
 

Return Value

A SugarCommand object.
Remarks
You can use this method as an alternative to common SugarCommand constructors.
Example
In this sample SugarCommand object is created. It is automatically associated with SugarConnection that created it.
public void CreateSugarCommand(string myConnString)
{
  SugarConnection sugarConnection = new SugarConnection(myConnString);
  SugarCommand sugarCommand = sugarConnection.CreateCommand();
  sugarCommand.CommandText = "INSERT INTO Campaigns (name, campaign_type, end_date, status) VALUES ('Sale campaign', 'Email', '2016-12-12', 'Active')";
  sugarConnection.Open();
  try
  {
    sugarCommand.ExecuteNonQuery();
  }
  finally
  {
    sugarConnection.Close();
  }
}
Public Sub CreateSugarCommand(ByVal myConnString As String)
  Dim sugarConnection As New SugarConnection(myConnString)
  Dim sugarCommand As SugarCommand = sugarConnection.CreateCommand()
  sugarCommand.CommandText = "INSERT INTO Campaigns (name, campaign_type, end_date, status) VALUES ('Sale campaign', 'Email', '2016-12-12', 'Active')"
  sugarConnection.Open()
  Try
    sugarCommand.ExecuteNonQuery()
  Finally
    sugarConnection.Close()
  End Try
End Sub
See Also