Represents an open connection to Magento.
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
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