首页 > 代码库 > RowState和DataRowVersion使用示例
RowState和DataRowVersion使用示例
using System;using System.Data;namespace TestApp{ class Program { static void Main(string[] args) { DataTable cars = new DataTable("Cars"); DataColumn vin = new DataColumn("Vin"); vin.DataType = typeof(string); vin.AllowDBNull = false; vin.Caption = "VIN"; cars.Columns.Add(vin); DataColumn manufactor = new DataColumn("Manufactor"); manufactor.DataType = typeof(string); manufactor.MaxLength = 100; manufactor.AllowDBNull = true; cars.Columns.Add(manufactor); DataRow dr = cars.NewRow(); dr[0] = "123456789ABCDE"; dr[1] = "VW"; cars.Rows.Add(dr); Console.WriteLine(GetDataRowInfo(dr, "Vin")); cars.AcceptChanges(); dr.BeginEdit(); dr[0] = "987654321ABCDE"; dr[1] = "NISSAN"; Console.WriteLine(GetDataRowInfo(dr, "Vin")); dr.EndEdit(); Console.WriteLine(GetDataRowInfo(dr, "Vin")); } static string GetDataRowInfo(DataRow row, string columnName) { string retVal = string.Format("RowState: {0} \t\n", row.RowState); foreach (string versionString in Enum.GetNames(typeof(DataRowVersion))) { DataRowVersion version = (DataRowVersion)Enum.Parse(typeof(DataRowVersion), versionString); if (row.HasVersion(version)) retVal += string.Format("Version: {0} Value: {1} \r\n", version, row[columnName, version]); else retVal += string.Format("Version: {0} does not exist. \r\n", version); } return retVal; } }}
运行结果:
RowState: Added
Version: Original does not exist.
Version: Current Value: 123456789ABCDE
Version: Proposed does not exist.
Version: Default Value: 123456789ABCDE
RowState: Unchanged
Version: Original Value: 123456789ABCDE
Version: Current Value: 123456789ABCDE
Version: Proposed Value: 987654321ABCDE
Version: Default Value: 987654321ABCDE
RowState: Modified
Version: Original Value: 123456789ABCDE
Version: Current Value: 987654321ABCDE
Version: Proposed does not exist.
Version: Default Value: 987654321ABCDE
RowState和DataRowVersion使用示例
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。