• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# DataColumn类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中DataColumn的典型用法代码示例。如果您正苦于以下问题:C# DataColumn类的具体用法?C# DataColumn怎么用?C# DataColumn使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



DataColumn类属于命名空间,在下文中一共展示了DataColumn类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: CancelEdit

        public void CancelEdit()
        {
            DataTable myTable = new DataTable("myTable");
            DataColumn dc = new DataColumn("Id", typeof(int));
            dc.Unique = true;
            myTable.Columns.Add(dc);
            myTable.Rows.Add(new object[] { 1 });
            myTable.Rows.Add(new object[] { 2 });
            myTable.Rows.Add(new object[] { 3 });

            DataRow myRow = myTable.Rows[0];
            myRow.BeginEdit();
            myRow[0] = 7;
            myRow.CancelEdit();

            // DataRow CancelEdit
            Assert.Equal(true, (int)myRow[0] == 1);
        }
开发者ID:dotnet,项目名称:corefx,代码行数:18,代码来源:DataRowTest2.cs


示例2: DataViewTest

        public DataViewTest()
        {
            _dataTable = new DataTable("itemTable");
            _dc1 = new DataColumn("itemId");
            _dc2 = new DataColumn("itemName");
            _dc3 = new DataColumn("itemPrice");
            _dc4 = new DataColumn("itemCategory");

            _dataTable.Columns.Add(_dc1);
            _dataTable.Columns.Add(_dc2);
            _dataTable.Columns.Add(_dc3);
            _dataTable.Columns.Add(_dc4);
            DataRow dr;
            _seed = 123;
            _rowCount = 5;
            _rndm = new Random(_seed);
            for (int i = 1; i <= _rowCount; i++)
            {
                dr = _dataTable.NewRow();
                dr["itemId"] = "item " + i;
                dr["itemName"] = "name " + _rndm.Next();
                dr["itemPrice"] = "Rs. " + (_rndm.Next() % 1000);
                dr["itemCategory"] = "Cat " + ((_rndm.Next() % 10) + 1);
                _dataTable.Rows.Add(dr);
            }
            _dataTable.AcceptChanges();
            _dataView = new DataView(_dataTable);
            _dataView.ListChanged += new ListChangedEventHandler(OnListChanged);
            _listChangedArgs = null;
        }
开发者ID:ericeil,项目名称:corefx,代码行数:30,代码来源:DataViewTest.cs


示例3: Key

		internal Key(DataTable table,DataColumn[] columns,ListSortDirection[] sort, DataViewRowState rowState, IExpression filter)
		{
			_table = table;
			_filter = filter;
			if (_filter != null)
				_tmpRow = _table.NewNotInitializedRow();
			_columns = columns;
			if (sort != null && sort.Length == columns.Length) {
				_sortDirection = sort;
			}
			else {
				_sortDirection = new ListSortDirection[columns.Length];
				for(int i=0; i < _sortDirection.Length; i++) {
					_sortDirection[i] = ListSortDirection.Ascending;
				}
			}

			if (rowState != DataViewRowState.None) {
				_rowStateFilter = rowState;
			}
			else {
				// FIXME : what is the correct value ?
				_rowStateFilter = DataViewRowState.CurrentRows;
			}
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:25,代码来源:Key.cs


示例4: MakeTable

        private DataTable MakeTable()
        {
            DataTable namesTable = new DataTable("Names");
            DataColumn idColumn = new DataColumn();


            idColumn.DataType = Type.GetType("System.Int32");
            idColumn.ColumnName = "Id";
            idColumn.AutoIncrement = true;
            namesTable.Columns.Add(idColumn);


            DataColumn fNameColumn = new DataColumn();
            fNameColumn.DataType = Type.GetType("System.String");
            fNameColumn.ColumnName = "Fname";
            fNameColumn.DefaultValue = "Fname";
            namesTable.Columns.Add(fNameColumn);

            DataColumn lNameColumn = new DataColumn();
            lNameColumn.DataType = Type.GetType("System.String");
            lNameColumn.ColumnName = "LName";
            lNameColumn.DefaultValue = "LName";
            namesTable.Columns.Add(lNameColumn);


            // Set the primary key for the table
            DataColumn[] keys = new DataColumn[1];
            keys[0] = idColumn;
            namesTable.PrimaryKey = keys;
            // Return the new DataTable.
            return namesTable;
        }
开发者ID:dotnet,项目名称:corefx,代码行数:32,代码来源:DataRowTest.cs


示例5: GetSortedSchemaRows

        internal static DbSchemaRow[] GetSortedSchemaRows(DataTable dataTable, bool returnProviderSpecificTypes)
        {
            DataColumn sortindex = dataTable.Columns[SchemaMappingUnsortedIndex];
            if (null == sortindex)
            {
                sortindex = new DataColumn(SchemaMappingUnsortedIndex, typeof(int));
                dataTable.Columns.Add(sortindex);
            }
            int count = dataTable.Rows.Count;
            for (int i = 0; i < count; ++i)
            {
                dataTable.Rows[i][sortindex] = i;
            };
            DbSchemaTable schemaTable = new DbSchemaTable(dataTable, returnProviderSpecificTypes);

            const DataViewRowState rowStates = DataViewRowState.Unchanged | DataViewRowState.Added | DataViewRowState.ModifiedCurrent;
            DataRow[] dataRows = dataTable.Select(null, "ColumnOrdinal ASC", rowStates);
            Debug.Assert(null != dataRows, "GetSchemaRows: unexpected null dataRows");

            DbSchemaRow[] schemaRows = new DbSchemaRow[dataRows.Length];

            for (int i = 0; i < dataRows.Length; ++i)
            {
                schemaRows[i] = new DbSchemaRow(schemaTable, dataRows[i]);
            }
            return schemaRows;
        }
开发者ID:dotnet,项目名称:corefx,代码行数:27,代码来源:DBSchemaRow.cs


示例6: CreateTestView

 private DataView CreateTestView()
 {
     DataTable dt1 = new DataTable("table1");
     DataColumn c1 = new DataColumn("col");
     dt1.Columns.Add(c1);
     dt1.Rows.Add(new object[] { "1" });
     return new DataView(dt1);
 }
开发者ID:dotnet,项目名称:corefx,代码行数:8,代码来源:DataRowViewTest.cs


示例7: CreateInstance

		internal static AbstractDataContainer CreateInstance(Type type, DataColumn column)
		{
			AbstractDataContainer container;
			switch (Type.GetTypeCode(type)) {
				case TypeCode.Int16 :
					container = new Int16DataContainer();
					break;
				case TypeCode.Int32 : 
					container = new Int32DataContainer();
					break;
				case TypeCode.Int64 :
					container = new Int64DataContainer();
					break;
				case TypeCode.String :
					container = new StringDataContainer();
					break;
				case TypeCode.Boolean:
					container = new BitDataContainer();
					break;
				case TypeCode.Byte :
					container = new ByteDataContainer();
					break;
				case TypeCode.Char :
					container = new CharDataContainer();
					break;
				case TypeCode.Double :
					container = new DoubleDataContainer();
					break;
				case TypeCode.SByte :
					container = new SByteDataContainer();
					break;
				case TypeCode.Single :
					container = new SingleDataContainer();
					break;
				case TypeCode.UInt16 :
					container = new UInt16DataContainer();
					break;
				case TypeCode.UInt32 :
					container = new UInt32DataContainer();
					break;
				case TypeCode.UInt64 :
					container = new UInt64DataContainer();
					break;
				case TypeCode.DateTime :
					container = new DateTimeDataContainer();
					break;
				case TypeCode.Decimal :
					container = new DecimalDataContainer();
					break;
				default :
					container = new ObjectDataContainer();
					break;
			}
			container._type = type;
			container._column = column;
			return container;
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:57,代码来源:DataContainer.cs


示例8: MakeParentTable

        private void MakeParentTable()
        {
            // Create a new Table
            _parentTable = new DataTable("ParentTable");
            _dataSet = new DataSet("XmlSchemaDataSet");
            DataColumn column;
            DataRow row;

            // Create new DataColumn, set DataType,
            // ColumnName and add to Table.
            column = new DataColumn();
            column.DataType = typeof(int);
            column.ColumnName = "id";
            column.Unique = true;
            // Add the Column to the DataColumnCollection.
            _parentTable.Columns.Add(column);

            // Create second column
            column = new DataColumn();
            column.DataType = typeof(string);
            column.ColumnName = "ParentItem";
            column.AutoIncrement = false;
            column.Caption = "ParentItem";
            column.Unique = false;
            // Add the column to the table
            _parentTable.Columns.Add(column);

            // Create third column.
            column = new DataColumn();
            column.DataType = typeof(int);
            column.ColumnName = "DepartmentID";
            column.Caption = "DepartmentID";
            // Add the column to the table.
            _parentTable.Columns.Add(column);

            // Make the ID column the primary key column.
            DataColumn[] PrimaryKeyColumns = new DataColumn[2];
            PrimaryKeyColumns[0] = _parentTable.Columns["id"];
            PrimaryKeyColumns[1] = _parentTable.Columns["DepartmentID"];
            _parentTable.PrimaryKey = PrimaryKeyColumns;

            _dataSet.Tables.Add(_parentTable);

            // Create three new DataRow objects and add 
            // them to the DataTable
            for (int i = 0; i <= 2; i++)
            {
                row = _parentTable.NewRow();
                row["id"] = i + 1;
                row["ParentItem"] = "ParentItem " + (i + 1);
                row["DepartmentID"] = i + 1;
                _parentTable.Rows.Add(row);
            }
        }
开发者ID:dotnet,项目名称:corefx,代码行数:54,代码来源:DataTableTest3.cs


示例9: Ctor

        public void Ctor()
        {
            string colName = "ColName";
            DataColumn col = new DataColumn();

            //These should all ctor without an exception
            col = new DataColumn(colName);
            col = new DataColumn(colName, typeof(int));
            col = new DataColumn(colName, typeof(int), null);
            col = new DataColumn(colName, typeof(int), null, MappingType.Attribute);
        }
开发者ID:dotnet,项目名称:corefx,代码行数:11,代码来源:DataColumnTest.cs


示例10: CreateDataSet

		DataSet CreateDataSet ()
		{
			DataSet ds = new DataSet (DbProviderFactories.CONFIG_SECTION_NAME);
			DataTable dt = ds.Tables.Add (DbProviderFactories.CONFIG_SEC_TABLE_NAME);
			DataColumn [] columns = new DataColumn [4];
			columns [0] = new DataColumn ("Name", typeof (string));
			columns [1] = new DataColumn ("Description", typeof (string));
			columns [2] = new DataColumn ("InvariantName", typeof (string));
			columns [3] = new DataColumn ("AssemblyQualifiedName", typeof (string));
			dt.Columns.AddRange (columns);
			dt.PrimaryKey = new DataColumn [] { columns [2] };
			return ds;
		}
开发者ID:jamescourtney,项目名称:mono,代码行数:13,代码来源:DbProviderFactoriesConfigurationHandler.cs


示例11: ColumnManager

        public ColumnManager(int numCols) {

            allowedNull = "-";
            columnData = new ArrayList(numCols);
            
            for (int i = 0; i < numCols; i++)
            {
                DataColumn<string> col = new DataColumn<string>("Column " + i);                
                columnData.Add(col);
                columnNames.Add("");
            }

            
        }
开发者ID:NickAndersonX,项目名称:xodb,代码行数:14,代码来源:ColumnManager.cs


示例12: AutoIncrement

        public void AutoIncrement()
        {
            DataColumn col = new DataColumn("Auto");
            col.AutoIncrement = true;
            col.AutoIncrementSeed = 0;
            col.AutoIncrementStep = 1;

            _tbl.Columns.Add(col);
            _tbl.Rows.Add(_tbl.NewRow());

            Assert.Equal(0, Convert.ToInt32(_tbl.Rows[0]["Auto"]));

            _tbl.Rows.Add(_tbl.NewRow());
            Assert.Equal(1, Convert.ToInt32(_tbl.Rows[1]["Auto"]));

            col.AutoIncrement = false;
            Assert.Equal(1, Convert.ToInt32(_tbl.Rows[1]["Auto"]));

            _tbl.Rows.Add(_tbl.NewRow());
            Assert.Equal(DBNull.Value, _tbl.Rows[2]["Auto"]);

            col.AutoIncrement = true;
            col.AutoIncrementSeed = 10;
            col.AutoIncrementStep = 2;

            _tbl.Rows.Add(_tbl.NewRow());
            Assert.Equal(10, Convert.ToInt32(_tbl.Rows[3]["Auto"]));
            _tbl.Rows.Add(_tbl.NewRow());
            Assert.Equal(12, Convert.ToInt32(_tbl.Rows[4]["Auto"]));

            col = new DataColumn("Auto2");
            col.DataType = typeof(string);
            col.AutoIncrement = true;
            col.AutoIncrementSeed = 0;
            col.AutoIncrementStep = 1;
            _tbl.Columns.Add(col);

            _tbl.Rows.Add(_tbl.NewRow());
            Assert.Equal(typeof(int), _tbl.Columns[1].DataType);
            Assert.Equal(typeof(int), _tbl.Rows[5]["Auto2"].GetType());

            col = new DataColumn("Auto3");
            col.AutoIncrement = true;
            col.AutoIncrementSeed = 0;
            col.AutoIncrementStep = 1;
            col.DataType = typeof(string);
            Assert.Equal(typeof(string), col.DataType);
            Assert.False(col.AutoIncrement);
        }
开发者ID:dotnet,项目名称:corefx,代码行数:49,代码来源:DataRowCollectionTest.cs


示例13: Generate

        public void Generate()
        {
            Exception tmpEx = new Exception();

            DataTable tbl = new DataTable();
            tbl.Columns.Add(new DataColumn("Column"));
            DataColumn dc = new DataColumn();
            dc.Expression = "something"; //invalid expression

            // SyntaxErrorException - Column Expression
            Assert.Throws<SyntaxErrorException>(() => tbl.Columns[0].Expression = "Colummn +=+ 1"); //invalid expression

            // SyntaxErrorException - Select 
            Assert.Throws<SyntaxErrorException>(() => tbl.Select("Name += something"));
        }
开发者ID:dotnet,项目名称:corefx,代码行数:15,代码来源:SyntaxErrorExceptionTest.cs


示例14: AllowDBNull

 public void AllowDBNull()
 {
     DataColumn col = new DataColumn("NullCheck", typeof(int));
     _tbl.Columns.Add(col);
     col.AllowDBNull = true;
     _tbl.Rows.Add(_tbl.NewRow());
     _tbl.Rows[0]["NullCheck"] = DBNull.Value;
     try
     {
         col.AllowDBNull = false;
         Assert.False(true);
     }
     catch (DataException)
     {
     }
 }
开发者ID:dotnet,项目名称:corefx,代码行数:16,代码来源:DataColumnTest.cs


示例15: CreateDataTables

 internal virtual void CreateDataTables (DataSet ds, XmlNode section) 
 {                        
         DataTable dt = ds.Tables.Add ("DbProviderFactories");
         DataColumn [] columns = new DataColumn [5];
         columns [0] = new DataColumn ("Name", typeof (string));
         columns [1] = new DataColumn ("Description", typeof (string));
         columns [2] = new DataColumn ("InvariantName", typeof (string));
         columns [3] = new DataColumn ("AssemblyQualifiedName", typeof (string));
         columns [4] = new DataColumn ("SupportedClasses", typeof (int));
         dt.Columns.AddRange (columns);
         dt.PrimaryKey = new DataColumn [] {columns [2]};
                 
         foreach (XmlNode node in section.SelectNodes (".//DbProviderFactories")) {
                 AddRows (dt, node);
                 RemoveRows (dt, node);
        }
 }
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:17,代码来源:DbProviderFactoriesConfigurationHandler.cs


示例16: DataRelationTest

        public DataRelationTest()
        {
            _set = new DataSet();
            _mom = new DataTable("Mom");
            _child = new DataTable("Child");
            _set.Tables.Add(_mom);
            _set.Tables.Add(_child);

            DataColumn Col = new DataColumn("Name");
            DataColumn Col2 = new DataColumn("ChildName");
            _mom.Columns.Add(Col);
            _mom.Columns.Add(Col2);

            DataColumn Col3 = new DataColumn("Name");
            DataColumn Col4 = new DataColumn("Age");
            Col4.DataType = Type.GetType("System.Int16");
            _child.Columns.Add(Col3);
            _child.Columns.Add(Col4);
        }
开发者ID:dotnet,项目名称:corefx,代码行数:19,代码来源:DataRelationTest.cs


示例17: Generate

        public void Generate()
        {
            Exception tmpEx = new Exception();

            DataTable tbl = new DataTable();
            tbl.Columns.Add(new DataColumn("Column"));
            DataColumn dc = new DataColumn();
            dc.Expression = "something"; //invalid expression

            // EvaluateException - Column 
            Assert.Throws<EvaluateException>(() =>
            {
                tbl.Columns.Add(dc);
            });

            // EvaluateException - Column Expression
            Assert.Throws<EvaluateException>(() =>
            {
                tbl.Columns[0].Expression = "Min(AK47)"; //invalid expression
            });
        }
开发者ID:dotnet,项目名称:corefx,代码行数:21,代码来源:EvaluateExceptionTest.cs


示例18: AllowDBNull

        public void AllowDBNull()
        {
            DataTable dt = new DataTable();
            DataColumn dc;
            dc = new DataColumn("ColName", typeof(int));
            dc.DefaultValue = DBNull.Value;
            dt.Columns.Add(dc);
            dc.AutoIncrement = false;

            // Checking default value (True)
            Assert.Equal(true, dc.AllowDBNull);

            // AllowDBNull=true - adding new row with null value
            dt.Rows.Add(dt.NewRow());
            Assert.Equal(DBNull.Value, dt.Rows[0][0]);

            // set AllowDBNull=false 
            Assert.Throws<DataException>(() =>
            {
                dc.AllowDBNull = false; //the exisiting row contains null value
            });

            dt.Rows.Clear();
            dc.AllowDBNull = false;
            // AllowDBNull=false - adding new row with null value
            Assert.Throws<NoNullAllowedException>(() =>
            {
                dt.Rows.Add(dt.NewRow());
            });

            dc.AutoIncrement = true;
            int iRowCount = dt.Rows.Count;
            // AllowDBNull=false,AutoIncrement=true - adding new row with null value
            dt.Rows.Add(dt.NewRow());
            Assert.Equal(dt.Rows.Count, iRowCount + 1);
        }
开发者ID:dotnet,项目名称:corefx,代码行数:36,代码来源:DataColumnTest2.cs


示例19: CreateChildViewSimple

        public void CreateChildViewSimple()
        {
            DataSet ds = new DataSet();

            DataTable dt1 = new DataTable("table1");
            ds.Tables.Add(dt1);
            DataColumn c1 = new DataColumn("col");
            dt1.Columns.Add(c1);
            dt1.Rows.Add(new object[] { "1" });

            DataTable dt2 = new DataTable("table2");
            ds.Tables.Add(dt2);
            DataColumn c2 = new DataColumn("col");
            dt2.Columns.Add(c2);
            dt2.Rows.Add(new object[] { "1" });

            DataRelation dr = new DataRelation("dr", c1, c2);

            DataView dv = new DataView(dt1);
            DataRowView dvr = dv[0];
            DataView v = dvr.CreateChildView(dr);
            Assert.Equal("", v.RowFilter);
            Assert.Equal("", v.Sort);
        }
开发者ID:dotnet,项目名称:corefx,代码行数:24,代码来源:DataRowViewTest.cs


示例20: UInt32Storage

 public UInt32Storage(DataColumn column)
 : base(column, typeof(UInt32), defaultValue, StorageType.UInt32) {
 }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:3,代码来源:UInt32Storage.cs



注:本文中的DataColumn类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# DataConnection类代码示例发布时间:2022-05-24
下一篇:
C# DataCollection类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap