DataStoreExtensions.Update(bool resetFlag, PbResultStyle resultStyle) Method
.NET Standard 2.x
Updates the database with the changes made in the DataStore.
Namespace: PowerScript.Bridge
Assembly: PowerScript.Bridge.dll
Syntax
public static int Update(this IDataStoreBase dataStore, bool resetFlag, PbResultStyle resultStyle);
Parameters
resetFlag
System.Boolean
A Boolean
value specifying whether DataStore should automatically reset the update flags.
True
-- to reset the flags.
False
-- not to reset the flags.
PbResultStyle
PowerScript.Bridge.PbResultStyle
The type of the return value.
PbResultStyle.AffectedRows
: returns the number of rows affected.
PbResultStyle.Flags
: returns the result of the function execution. 1
indicates success, -1
indicates failure.
Returns
System.Int32
PbResultStyle.AffectedRows
:
Returns the number of the rows affected if it succeeds, and -1
if canceled.
PbResultStyle.Flags
:
Returns 1
if it succeeds and -1
if an error occurs.
Examples
The following code example adds a data record to the end of the DataStore and then updates the change to the database.
using System;
using DWNet.Data;
using PowerScript.Bridge;
namespace Appeon.ApiDoc.DataStoreExtensionsExamples
{
public class UpdateExample
{
private readonly SchoolContext _context;
public UpdateExample(SchoolContext dataContext)
{
// Sets the data context
_context = dataContext;
}
public void Example()
{
// Instantiates a DataStore object with datawindow: d_department.
var datastore = new DataStore("d_department", _context);
Console.WriteLine("Retrieved Rowcount: {0}", datastore.Retrieve());
// Adds a row to the end of DataStore.
int row = datastore.AddRow();
datastore.SetItem(row, "Departmentid", 10);
datastore.SetItem(row, "Name", "New Department");
datastore.SetItem(row, "Budget", 10000m);
datastore.SetItem(row, "Startdate", DateTime.Now);
datastore.SetItem(row, "Administrator", 2);
// Calls Update to commit changes to database.
// Returns 1 if update is successful
int result = datastore.Update(true, PbResultStyle.Flags);
Console.WriteLine("After Add, Update and Retrieve, Rowcount: {0}",
datastore.Retrieve());
Console.WriteLine("Update returns a value: {0}", result);
/*This code produces the following output:
Retrieved Rowcount: 4
After Add, Update and Retrieve, Rowcount: 5
Update returns a value: 1
*/
}
}
}
Example Refer To
Model Class: D_Department
DataWindow File: d_department
Applies to
.NET Standard
2.x