Represents an open connection to Adobe Commerce.
The following example creates a
MagentoCommand and a
MagentoConnection. The
MagentoConnection 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 magentoConnectionString)
{
// If the connection string is empty, use default.
if(magentoConnectionString == "")
{
magentoConnectionString =
"domain=192.168.10.68/magento;user=Test;apikey=testpassword;";
}
MagentoConnection myConn = new MagentoConnection(magentoConnectionString);
string myInsertQuery = "INSERT INTO Customers (email, firstname, lastname) VALUES ('[email protected]', 'John', 'Smith')";
MagentoCommand magentoCommand = new MagentoCommand(myInsertQuery);
magentoCommand.Connection = myConn;
myConn.Open();
try
{
magentoCommand.ExecuteNonQuery();
}
finally
{
myConn.Close();
}
} |
|
|---|
Public Sub InsertRow(magentoConnectionString As String)
' If the connection string is empty, use default.
If magentoConnectionString = "" Then
magentoConnectionString = _
"domain=192.168.10.68/magento;user=Test;apikey=testpassword;"
End If
Dim myConn As New MagentoConnection(magentoConnectionString)
Dim myInsertQuery As String = "INSERT INTO Customers (email, firstname, lastname) VALUES ('[email protected]', 'John', 'Smith')"
Dim magentoCommand As New MagentoCommand(myInsertQuery)
magentoCommand.Connection = myConn
myConn.Open()
Try
magentoCommand.ExecuteNonQuery()
Finally
myConn.Close()
End Try
End Sub |