In This Topic
You can update the ExactTarget data either by modifying data returned by the ExactTargetDataAdapter class and then calling its Update method or by performing corresponding DML statements (INSERT, DELETE, UPDATE) via ExactTargetCommand.
Here is an example showing how to update ExactTarget data using ExactTargetDataAdapter.
using Devart.Data.ExactTarget;
...
class Program
{
static void Main(string[] args) {
var monitor = new Devart.Data.ExactTarget.ExactTargetMonitor() { IsActive = true };
const string connectionString = "user=MyCompanyAdmin;password=mypassword;url=https://webservice.s7.exacttarget.com/Service.asmx;";
const string sql = "SELECT ID, Name FROM Email";
using (ExactTargetConnection connection = new ExactTargetConnection(connectionString)) {
connection.Open();
DataTable table = new DataTable("Email");
using (ExactTargetCommand command = connection.CreateCommand()) {
command.CommandText = sql;
using (ExactTargetDataAdapter adapter = new ExactTargetDataAdapter(command)) {
adapter.Fill(table);
adapter.UpdateCommand = new ExactTargetCommand("UPDATE Email SET Name = @name WHERE ID = @id", connection);
adapter.UpdateCommand.Parameters.Add("id", DbType.String).SourceColumn = "ID";
adapter.UpdateCommand.Parameters["id"].SourceVersion = DataRowVersion.Original;
adapter.UpdateCommand.Parameters.Add("name", DbType.String).SourceColumn = "Name";
DataRow firstrow = table.Rows[0];
firstrow["Name"] = "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.ExactTarget
...
Module Module1
Sub Main()
Const connectionString As String = "user=MyCompanyAdmin;password=mypassword;url=https://webservice.s7.exacttarget.com/Service.asmx;"
Const sql As String = "SELECT ID, Name FROM Email"
Using connection As New ExactTargetConnection(connectionString)
connection.Open()
Dim table As New DataTable("Email")
Using command As ExactTargetCommand = connection.CreateCommand()
command.CommandText = sql
Using adapter As New ExactTargetDataAdapter(command)
adapter.Fill(table)
adapter.UpdateCommand = New ExactTargetCommand("UPDATE Email SET Name = @name WHERE ID = @id", connection)
adapter.UpdateCommand.Parameters.Add("id", DbType.String).SourceColumn = "ID"
adapter.UpdateCommand.Parameters("id").SourceVersion = DataRowVersion.Original
adapter.UpdateCommand.Parameters.Add("name", DbType.String).SourceColumn = "Name"
Dim firstrow As DataRow = table.Rows(0)
firstrow("Name") = "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 ExactTarget data using ExactTargetCommand.
using Devart.Data.ExactTarget;
...
class Program
{
static void Main(string[] args) {
const string connectionString = "user=MyCompanyAdmin;password=mypassword;url=https://webservice.s7.exacttarget.com/Service.asmx;";
const string sql = "UPDATE Email SET Subject = 'sample subject 1' WHERE Name = 'sample name 1'";
using (ExactTargetConnection connection = new ExactTargetConnection(connectionString)) {
connection.Open();
using (ExactTargetCommand command = connection.CreateCommand()) {
command.CommandText = sql;
Console.WriteLine(command.ExecuteNonQuery());
}
}
Console.ReadKey();
}
}
Imports Devart.Data.ExactTarget
...
Module Module1
Sub Main()
Const connectionString As String = "user=MyCompanyAdmin;password=mypassword;url=https://webservice.s7.exacttarget.com/Service.asmx;"
Const sql As String = "UPDATE Email SET Subject = 'sample subject 1' WHERE Name = 'sample name 1'"
Using connection As New ExactTargetConnection(connectionString)
connection.Open()
Using command As ExactTargetCommand = 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