Skip to main content
Version: 8.2

Add data to the database

Level: advanced
note

The examples in this article are also implemented in the web service. The package that contains the web service implementation is attached in the Resources block.

Example 1

Example

Add the contact that has the specified name.

InsertContact() method
public string InsertContact(string contactName) {
contactName = contactName ?? "Unknown contact";
var ins = new Insert(UserConnection)
.Into("Contact")
.Set("Name", Column.Parameter(contactName));
var affectedRows = ins.Execute();
var result = $ "Inserted new contact with name '{contactName}'. {affectedRows} rows affected";
return result;
}

Example 2

Example

Add the city that has the specified name and connect it to the specified country.

InsertCity() method
public string InsertCity(string city, string country) {
city = city ?? "unknown city";
country = country ?? "unknown country";

var ins = new Insert(UserConnection)
.Into("City")
.Set("Name", Column.Parameter(city))
.Set("CountryId",
new Select(UserConnection)
.Top(1)
.Column("Id")
.From("Country")
.Where("Name")
.IsEqual(Column.Parameter(country)));
var affectedRows = ins.Execute();
var result = $ "Inserted new city with name '{city}' located in '{country}'. {affectedRows} rows affected";
return result;
}

Resources

Package with example implementation (web service)