In This Topic
You can update the Magento data either by modifying data returned by the MagentoDataAdapter class and then calling its Update method or by performing corresponding DML statements (INSERT, DELETE, UPDATE) via MagentoCommand.
Here is an example showing how to update Magento data using MagentoDataAdapter.
using Devart.Data.Magento;
...
class Program
{
static void Main(string[] args) {
const string connectionString = "domain=192.168.10.68/magento;user=Test;apikey=testpassword;";
const string sql = "SELECT customer_id, LastName FROM Customers";
using (MagentoConnection connection = new MagentoConnection(connectionString)) {
connection.Open();
DataTable table = new DataTable("Customers");
using (MagentoCommand command = connection.CreateCommand()) {
command.CommandText = sql;
using (MagentoDataAdapter adapter = new MagentoDataAdapter(command)) {
adapter.Fill(table);
adapter.UpdateCommand = new MagentoCommand("UPDATE Customers SET LastName = @name WHERE customer_id = @id", connection);
adapter.UpdateCommand.Parameters.Add("id", DbType.String).SourceColumn = "customer_id";
adapter.UpdateCommand.Parameters["id"].SourceVersion = DataRowVersion.Original;
adapter.UpdateCommand.Parameters.Add("name", DbType.String).SourceColumn = "LastName";
DataRow firstrow = table.Rows[0];
firstrow["LastName"] = "sample name 1";
Console.WriteLine(adapter.Update(table));
}
}
Console.WriteLine("Rows after update.");
foreach (DataRow row in table.Rows) {
Console.WriteLine("{0}\t{1}", row[0], row[1]);
}
}
Console.ReadKey();
}
}
Imports Devart.Data.Magento
...
Module Module1
Sub Main()
Const connectionString As String = "domain=192.168.10.68/magento;user=Test;apikey=testpassword;"
Const sql As String = "SELECT customer_id, LastName FROM Customers"
Using connection As New MagentoConnection(connectionString)
connection.Open()
Dim table As New DataTable("Customers")
Using command As MagentoCommand = connection.CreateCommand()
command.CommandText = sql
Using adapter As New MagentoDataAdapter(command)
adapter.Fill(table)
adapter.UpdateCommand = New MagentoCommand("UPDATE Customers SET LastName = @name WHERE customer_id = @id", connection)
adapter.UpdateCommand.Parameters.Add("id", DbType.String).SourceColumn = "customer_id"
adapter.UpdateCommand.Parameters("id").SourceVersion = DataRowVersion.Original
adapter.UpdateCommand.Parameters.Add("name", DbType.String).SourceColumn = "LastName"
Dim firstrow As DataRow = table.Rows(0)
firstrow("LastName") = "sample name 1"
Console.WriteLine(adapter.Update(table))
Console.WriteLine("Rows after update.")
For Each row As DataRow In table.Rows
Console.WriteLine(row(0).ToString() & vbTab & row(1))
Next
End Using
End Using
End Using
Console.ReadKey()
End Sub
End Module
The following example updates Magento data using MagentoCommand.
using Devart.Data.Magento;
...
class Program
{
static void Main(string[] args) {
const string connectionString = "domain=192.168.10.68/magento;user=Test;apikey=testpassword;";
const string sql = "UPDATE Customers SET Email = '[email protected]' WHERE LastName = 'sample name 1'";
using (MagentoConnection connection = new MagentoConnection(connectionString)) {
connection.Open();
using (MagentoCommand command = connection.CreateCommand()) {
command.CommandText = sql;
Console.WriteLine(command.ExecuteNonQuery());
}
}
Console.ReadKey();
}
}
Imports Devart.Data.Magento
...
Module Module1
Sub Main()
Const connectionString As String = "domain=192.168.10.68/magento;user=Test;apikey=testpassword;"
Const sql As String = "UPDATE Customers SET Email = '[email protected]' WHERE LastName = 'sample name 1'"
Using connection As New MagentoConnection(connectionString)
connection.Open()
Using command As MagentoCommand = connection.CreateCommand()
command.CommandText = sql
Console.WriteLine(command.ExecuteNonQuery())
End Using
End Using
Console.ReadKey()
End Sub
End Module
See Also
Entity Framework
| Retrieving Data