Đang chuẩn bị liên kết để tải về tài liệu:
Using Auto-Incrementing Columns Without Causing Conflicts

Không đóng trình duyệt đến khi xuất hiện nút TẢI XUỐNG

[ Team LiB ] Recipe 4.1 Using Auto-Incrementing Columns Without Causing Conflicts Problem You want to use an AutoIncrement column in a table without producing values that may be duplicated in records added by other users. Solution Use the AutoIncrementSeed and AutoIncrementStep properties of the AutoIncrement column. | Team LiB Recipe 4.1 Using Auto-Incrementing Columns Without Causing Conflicts Problem You want to use an AutoIncrement column in a table without producing values that may be duplicated in records added by other users. Solution Use the AutoIncrementSeed and AutoIncrementStep properties of the AutoIncrement column. The sample code contains two event handlers Form.Load Sets up the sample by creating a DataTable and programmatically defining the schema to match the Categories table in Northwind. The AutoIncrementSeed and AutoIncrementStep property values are both set to -1 for the AutoIncrement primary key column the CategoryID. A DataAdapter is created and used to fill the DataTable. The default view of the table is bound to the data grid on the form. Add Button.Click Creates a new row in the Categories DataTable using the entered CategoryName and Description values and the automatically generated CategoryID field. The C code is shown in Example 4-1. Example 4-1. File AutoIncrementWithoutConflictForm.es Namespaces variables and constants using System using System.Configuration using System.Data using System.Data.SqlClient Table name constants private const String CATEGORIES_TABLE Categories Field name constants private const String CATEGORYID_FIELD CategoryID private const String CATEGORYNAME_FIELD CategoryName private const String DESCRIPTION_FIELD Description private DataTable dt . . . private void AutoIncrementWithoutConflictForm_Load object sender System.EventArgs e Create the Categories table. dt new DataTable CATEGORIES_TABLE Add the identity column. DataColumn col dt.Columns.Add CATEGORYID_FIELD typeof System.Int32 col.AllowDBNull false col.AutoIncrement true col.AutoIncrementSeed -1 col.AutoIncrementStep -1 Set the primary key. dt.PrimaryKey new DataColumn col Add the other columns. col dt.Columns.Add CATEGORYNAME_FIELD typeof System.String col.AllowDBNull false col.MaxLength 15 dt.Columns.Add DESCRIPTION_FIELD typeof System.String Fill the table. .

TÀI LIỆU LIÊN QUAN
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.