IDataStoreBase.SetItemStatus(int row, string column, DwBuffer bufferType, PropertyState status) Method
.NET Standard 2.x
Sets the modification status in the column (by the column name) for a row in the specified buffer in the DataStore. The column modification status along with row modification status determines the type of SQL statement the Update
method will generate for the row.
Namespace: DWNet.Data
Assembly: DWNet.Data.dll
Syntax
public bool SetItemStatus(int row, string column, DwBuffer bufferType, PropertyState status);
Parameters
row
System.Int32
The zero-based index number of the row in which you want to set the status.
column
System.String
The name of the column in which you want to set the status.
bufferType
DWNet.Data.DwBuffer
A value identifying the DataWindow buffer
that contains the row.
status
SnapObjects.Data.PropertyState
A value of the PropertyState
enumerated datatype specifying the new status.
Returns
System.Boolean
Returns true
if it succeeds.
Remarks
When data is retrieved
When data is retrieved into a DataStore, all columns initially have a status of PropertyState.NotModified
. After data has changed in a column in a particular row, such as through the SetItem
method, the status for that column changes to PropertyState.Modified
. Once the status for any column in a retrieved row changes to PropertyState.Modified
, the row status also changes to ModelState.Modified
.
When rows are inserted
When a row is inserted into a DataStore, it initially has a row status of ModelState.New
, and all columns in that row initially have a status of PropertyState.NotModified
. After data has changed in a column in the row, such as through the SetItem
method, the column status changes to PropertyState.Modified
. Once the status for any column in the inserted row changes to PropertyState.Modified
, the row status changes to ModelState.NewModified
.
When a DataStore column has a default value, the column status does not change to PropertyState.Modified
until the user makes at least one actual change to a column in that row.
When Update is called
A row's status flag determines what SQL command the Update
method uses to update the database. INSERT or UPDATE is called, depending upon the following row statuses:
Row status | SQL statement generated |
---|---|
ModelState.NewModified |
INSERT |
ModelState.Modified |
UPDATE |
A column is included in an UPDATE statement only if the following two conditions are met:
The column is on the updatable column list maintained by the
DataWindow object
.The column has a status of
PropertyState.Modified
.The DataStore includes all columns in INSERT statements it generates.
Examples
The following code example uses the SetItemStatus
to modify the status for the name column in the first row.
using SnapObjects.Data;
using DWNet.Data;
using System;
namespace Appeon.ApiDoc.IDataStoreBaseExamples
{
public class SetItemStatusExample
{
private readonly SchoolContext _context;
public SetItemStatusExample(SchoolContext dataContext)
{
// Sets the data context
_context = dataContext;
}
public void Example2()
{
// Instantiates a DataStore object with datawindow: d_department.
var datastore = new DataStore("d_department", _context);
// Retrieves rows from the database for datastore.
datastore.Retrieve();
Console.WriteLine("After Retrieve, Rowcount: {0}",
datastore.RowCount);
// Sets the value for the second column in the first row to "New Department".
datastore.SetItem(0, 1, "New Department");
Console.WriteLine("Gets the original status of name: {0}",
datastore.GetItemStatus(0, "name", DwBuffer.Primary));
Console.WriteLine("Before SetItemStatus, Modifiedcount: {0}",
datastore.ModifiedCount);
// Sets the status for the name column in the first row to NotModified.
datastore.SetItemStatus(0, "name", DwBuffer.Primary,
PropertyState.NotModified);
Console.WriteLine("Gets the modified status of name: {0}",
datastore.GetItemStatus(0, "name", DwBuffer.Primary));
Console.WriteLine("After SetItemStatus, Modifiedcount: {0}",
datastore.ModifiedCount);
/*This code produces the following output:
After Retrieve, Rowcount: 4
Gets the original status of name: Modified
Before SetItemStatus, Modifiedcount: 1
Gets the modified status of name: NotModified
After SetItemStatus, Modifiedcount: 0
*/
}
}
}
Example Refer To
Model Class: D_Department
DataWindow File: d_department
Applies to
.NET Standard
2.x