In This Topic
You can update the FreshBooks data either by modifying data returned by the FreshBooksDataAdapter class and then calling its Update method or by performing corresponding DML statements (INSERT, DELETE, UPDATE) via FreshBooksCommand.
Here is an example showing how to update FreshBooks data using FreshBooksDataAdapter.
using Devart.Data.FreshBooks;
...
class Program
{
static void Main(string[] args) {
const string connectionString = "Server=newcompany1111.freshbooks.com;Authentication Token=d2edadb1d00dfb2ff1209f0409952e70;";
const string sql = "SELECT id, Name FROM Task";
using (FreshBooksConnection connection = new FreshBooksConnection(connectionString)) {
connection.Open();
DataTable table = new DataTable("Task");
using (FreshBooksCommand command = connection.CreateCommand()) {
command.CommandText = sql;
using (FreshBooksDataAdapter adapter = new FreshBooksDataAdapter(command)) {
adapter.Fill(table);
adapter.UpdateCommand = new FreshBooksCommand("UPDATE Task 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.FreshBooks
...
Module Module1
Sub Main()
Const connectionString As String = "Server=newcompany1111.freshbooks.com;Authentication Token=d2edadb1d00dfb2ff1209f0409952e70;"
Const sql As String = "SELECT id, Name FROM Task"
Using connection As New FreshBooksConnection(connectionString)
connection.Open()
Dim table As New DataTable("Task")
Using command As FreshBooksCommand = connection.CreateCommand()
command.CommandText = sql
Using adapter As New FreshBooksDataAdapter(command)
adapter.Fill(table)
adapter.UpdateCommand = New FreshBooksCommand("UPDATE Task 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 FreshBooks data using FreshBooksCommand.
using Devart.Data.FreshBooks;
...
class Program
{
static void Main(string[] args) {
const string connectionString = "Server=newcompany1111.freshbooks.com;Authentication Token=d2edadb1d00dfb2ff1209f0409952e70;";
const string sql = "UPDATE Task SET Rate = 100 WHERE Name = 'sample name 1'";
using (FreshBooksConnection connection = new FreshBooksConnection(connectionString)) {
connection.Open();
using (FreshBooksCommand command = connection.CreateCommand()) {
command.CommandText = sql;
Console.WriteLine(command.ExecuteNonQuery());
}
}
Console.ReadKey();
}
}
Imports Devart.Data.FreshBooks
...
Module Module1
Sub Main()
Const connectionString As String = "Server=newcompany1111.freshbooks.com;Authentication Token=d2edadb1d00dfb2ff1209f0409952e70;"
Const sql As String = "UPDATE Task SET Rate = 100 WHERE Name = 'sample name 1'"
Using connection As New FreshBooksConnection(connectionString)
connection.Open()
Using command As FreshBooksCommand = 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