当前位置: 首页>>代码示例>>C#>>正文


C# Data.DataColumn类代码示例

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


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

示例1: GetReady

		public void GetReady ()
		{
			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:Profit0004,项目名称:mono,代码行数:29,代码来源:DataViewTest.cs

示例2: CreateDataTable

        private DataTable CreateDataTable()
        {
            DataTable table = new DataTable();
            DataColumn column1 = new DataColumn("Id", typeof(string));
            DataColumn column2 = new DataColumn("Text", typeof(String));
            DataColumn column3 = new DataColumn("ParentId", typeof(string));
            table.Columns.Add(column1);
            table.Columns.Add(column2);
            table.Columns.Add(column3);

            DataRow row = table.NewRow();
            row[0] = "china";
            row[1] = "中国";
            row[2] = DBNull.Value;
            table.Rows.Add(row);

            row = table.NewRow();
            row[0] = "henan";
            row[1] = "河南省";
            row[2] = "china";
            table.Rows.Add(row);

            row = table.NewRow();
            row[0] = "zhumadian";
            row[1] = "驻马店市";
            row[2] = "henan";
            table.Rows.Add(row);

            row = table.NewRow();
            row[0] = "luohe";
            row[1] = "漯河市";
            row[2] = "henan";
            table.Rows.Add(row);

            row = table.NewRow();
            row[0] = "anhui";
            row[1] = "安徽省";
            row[2] = "china";
            table.Rows.Add(row);

            row = table.NewRow();
            row[0] = "hefei";
            row[1] = "合肥市";
            row[2] = "anhui";
            table.Rows.Add(row);

            row = table.NewRow();
            row[0] = "golden";
            row[1] = "金色池塘小区";
            row[2] = "hefei";
            table.Rows.Add(row);

            row = table.NewRow();
            row[0] = "ustc";
            row[1] = "中国科学技术大学";
            row[2] = "hefei";
            table.Rows.Add(row);

            return table;
        }
开发者ID:proson,项目名称:Fine-UI,代码行数:60,代码来源:tree_datatable.aspx.cs

示例3: GetAllProducts

    public DataTable GetAllProducts()
    {
        DataTable dt = new DataTable();
        DataRow dr;
        DataColumn dc;

        dc = new DataColumn("ID", typeof(Int32));
        dc.Unique = true;
        dt.Columns.Add(dc);

        dt.Columns.Add(new DataColumn("ProductName", typeof(string)));
        dt.Columns.Add(new DataColumn("Description", typeof(string)));
        dt.Columns.Add(new DataColumn("Price", typeof(string)));

        for (int i = 0; i < 10000; i++)
        {
            dr = dt.NewRow();
            dr["id"] = i;
            dr["ProductName"] = "Product " + i;
            dr["Description"] = "Description for Product " + i;
            dr["Price"] = "$100";
            dt.Rows.Add(dr);
        }
        return dt;
    }
开发者ID:satripat,项目名称:test,代码行数:25,代码来源:DataLayer.cs

示例4: PopulateReceivingFieldList

        private void PopulateReceivingFieldList()
        {
            string CheckedMember = "CHECKED";
            string DisplayMember = "Field Name";
            string ValueMember = "Field Key";

            FFieldTable = TRemote.MFinance.Reporting.WebConnectors.GetReceivingFields(FLedgerNumber, out DisplayMember, out ValueMember);

            DataColumn FirstColumn = new DataColumn(CheckedMember, typeof(bool));

            FirstColumn.DefaultValue = false;
            FFieldTable.Columns.Add(FirstColumn);

            clbFields.Columns.Clear();
            clbFields.AddCheckBoxColumn("", FFieldTable.Columns[CheckedMember], 17, false);
            clbFields.AddTextColumn(Catalog.GetString("Field Key"), FFieldTable.Columns[ValueMember], 100);
            clbFields.AddTextColumn(Catalog.GetString("Field Name"), FFieldTable.Columns[DisplayMember], 200);
            clbFields.DataBindGrid(FFieldTable, ValueMember, CheckedMember, ValueMember, false, true, false);

            FTypeTable = TDataCache.TMPartner.GetCacheablePartnerTable(TCacheablePartnerTablesEnum.PartnerTypeList);

            DataColumn CheckedColumn = new DataColumn(CheckedMember, typeof(bool));
            CheckedColumn.DefaultValue = false;

            FTypeTable.Columns.Add(CheckedColumn);
            clbTypes.Columns.Clear();
            clbTypes.AddCheckBoxColumn("", FTypeTable.Columns[CheckedMember], 17);
            clbTypes.AddTextColumn(Catalog.GetString("Partner Type"), FTypeTable.Columns[PTypeTable.GetTypeCodeDBName()], 280);
            clbTypes.DataBindGrid(FTypeTable, PTypeTable.GetTypeCodeDBName(), CheckedMember,
                PTypeTable.GetTypeCodeDBName(), false, true, false);
        }
开发者ID:Davincier,项目名称:openpetra,代码行数:31,代码来源:TotalGivingForRecipients.ManualCode.cs

示例5: ReadTable

 public static DataTable ReadTable(DbCommand cmd)
 {
     DataTable dt = new DataTable();
     DbDataReader reader = null;
     try
     {
         reader = cmd.ExecuteReader();
         int fieldc = reader.FieldCount;
         for (int i = 0; i < fieldc; i++)
         {
             DataColumn dc = new DataColumn(reader.GetName(i), reader.GetFieldType(i));
             dt.Columns.Add(dc);
         }
         while (reader.Read())
         {
             DataRow dr = dt.NewRow();
             for (int i = 0; i < fieldc; i++)
             {
                 dr[i] = reader[i];
             }
             dt.Rows.Add(dr);
         }
         return dt;
     }
     finally
     {
         if (reader != null) reader.Close();
     }
 }
开发者ID:503945930,项目名称:baoxin,代码行数:29,代码来源:HelperBase.cs

示例6: DesignColumn

 public DesignColumn()
 {
     this.namingPropNames = new StringCollection();
     this.dataColumn = new System.Data.DataColumn();
     this.designTable = null;
     this.namingPropNames.Add("typedName");
 }
开发者ID:Reegenerator,项目名称:Sample-CustomizeDatasetCS,代码行数:7,代码来源:DesignColumn.cs

示例7:

 private static FieldBuilder CréeAttributs(TypeBuilder constructeurDeType, DataColumn colonne)
 {
     FieldBuilder champBldr = null;
     PropertyBuilder constructeurPropriété;
     #region Création de l'attribut
     champBldr = constructeurDeType.DefineField(colonne.ColumnName.ToLower(), colonne.DataType, FieldAttributes.Private);
     #endregion
     #region Création de la Propriété associée
     constructeurPropriété = constructeurDeType.DefineProperty(colonne.ColumnName, System.Reflection.PropertyAttributes.HasDefault, colonne.DataType, null);
     // Choix des attributs
     MethodAttributes attrGetSet = MethodAttributes.Public |
        MethodAttributes.SpecialName | MethodAttributes.HideBySig;
     #region Définition du "getter".
     MethodBuilder constructeurGet = constructeurDeType.DefineMethod("get_" + colonne.ColumnName, attrGetSet, colonne.DataType, Type.EmptyTypes);
     ILGenerator champGetIL = constructeurGet.GetILGenerator();
     champGetIL.Emit(OpCodes.Ldarg_0);
     champGetIL.Emit(OpCodes.Ldfld, champBldr);
     champGetIL.Emit(OpCodes.Ret);
     #endregion
     #region Définition du "setter".
     MethodBuilder constructeurSet = constructeurDeType.DefineMethod("set_" + colonne.ColumnName, attrGetSet, null, new Type[] { colonne.DataType });
     ILGenerator champSetIL = constructeurSet.GetILGenerator();
     champSetIL.Emit(OpCodes.Ldarg_0);
     champSetIL.Emit(OpCodes.Ldarg_1);
     champSetIL.Emit(OpCodes.Stfld, champBldr);
     champSetIL.Emit(OpCodes.Ret);
     #endregion
     #region Association des accesseurs à la propriété
     constructeurPropriété.SetGetMethod(constructeurGet);
     constructeurPropriété.SetSetMethod(constructeurSet);
     #endregion
     #endregion
     return champBldr;
     }
开发者ID:kevmarzin,项目名称:ProjetBD,代码行数:34,代码来源:Construit.cs

示例8: btnCreate_Click

 protected void btnCreate_Click(object sender, EventArgs e)
 {
     //为DataTable指定一个表名,通过dt.TableName可以访问表名
     DataTable dt = new DataTable("内存表示例");
     //为DataTable添加架构信息,也就是创建字段
     dt.Columns.Add(new DataColumn("书名", typeof(string)));
     dt.Columns.Add(new DataColumn("书号", typeof(string)));
     //使用数组的形式创建表列
     DataColumn[] dcs = new DataColumn[2];
     dcs[0] = new DataColumn("价格", typeof(decimal));
     dcs[1] = new DataColumn("出版社", typeof(string));
     //调用DataTable的Columns集合的AddRange方法添加列
     dt.Columns.AddRange(dcs);
     //初始化新的行
     DataRow dr = dt.NewRow();
     //为DataRow中的列赋字值
     dr["书名"] = "C#编程系列";
     dr["书号"] = "12345-678-90";
     dr["价格"] = 45.3;
     dr["出版社"] = "我的出版社";
     //必须将创建的行添加的DataTable的Rows集合中。
     dt.Rows.Add(dr);
     //也可以使用Rows的重载的Add方法来添加表列
     dt.Rows.Add(new object[] { "C#编程系列二", "33455-333-333", 45.7, "我的出版社" });
     //绑定到GridView对象
     GridView1.DataSource = dt;
     GridView1.DataBind();
 }
开发者ID:AJLoveChina,项目名称:workAtQmm,代码行数:28,代码来源:MemoryDataTable.aspx.cs

示例9: ExecuteFormula

        public static void ExecuteFormula(string formula,decimal omset, decimal tarif)
        {
            DataTable table = new DataTable();
            // Create the first column.
            DataColumn omsetColumn = new DataColumn();
            omsetColumn.DataType = System.Type.GetType("System.Decimal");
            omsetColumn.ColumnName = "Omset";
            omsetColumn.DefaultValue = omset;

            // Create the first column.
            DataColumn tarifColumn = new DataColumn();
            tarifColumn.DataType = System.Type.GetType("System.Decimal");
            tarifColumn.ColumnName = "Tarif";
            tarifColumn.DefaultValue = tarif;

            // Create the second, calculated, column.
            DataColumn bagiHasilColumn = new DataColumn();
            bagiHasilColumn.DataType = System.Type.GetType("System.Decimal");
            bagiHasilColumn.ColumnName = "BagiHasil";
            bagiHasilColumn.Expression = formula;

            // Add columns to DataTable.
            table.Columns.Add(omsetColumn);
            table.Columns.Add(tarifColumn);
            table.Columns.Add(bagiHasilColumn);

            DataRow row = table.NewRow();
            table.Rows.Add(row);
            //DataView view = new DataView(table);
            // dataGrid1.DataSource = view;
            //Assert.AreEqual(909.09,row["BagiHasil"])
            Console.WriteLine("909.09 = {0}", row["BagiHasil"]);
            Console.Read();
        }
开发者ID:BonaStoco,项目名称:AP2,代码行数:34,代码来源:Program.cs

示例10: CreateGoogleDataColumn

        /// 
        /// <param name="column"></param>
        public static GoogleDataColumn CreateGoogleDataColumn(DataColumn column)
        {
            switch (column.DataType.FullName)
            {
                case "System.Boolean": return new BooleanGoogleDataColumn(column);
                case "System.Byte": return new NumberGoogleDataColumn(column);
                case "System.Char": return new StringGoogleDataColumn(column);
                case "System.DateTime":
                    if (column.ExtendedProperties.ContainsKey("GoogleDateType"))
                    {
                        switch ((GoogleDateType)column.ExtendedProperties["GoogleDateType"])
                        {
                            case GoogleDateType.Date: return new DateGoogleDataColumn(column);
                            case GoogleDateType.TimeOfDay: return new TimeOfDayGoogleDataColumn(column);
                            default: return new DateTimeGoogleDataColumn(column);
                        }
                    }
                    else
                        return new DateTimeGoogleDataColumn(column);

                case "System.Decimal": return new NumberGoogleDataColumn(column);
                case "System.Double": return new NumberGoogleDataColumn(column);
                case "System.Int16": return new NumberGoogleDataColumn(column);
                case "System.Int32": return new NumberGoogleDataColumn(column);
                case "System.Int64": return new NumberGoogleDataColumn(column);
                case "System.SByte": return new NumberGoogleDataColumn(column);
                case "System.Single": return new NumberGoogleDataColumn(column);
                case "System.String": return new StringGoogleDataColumn(column);
                case "System.TimeSpan": return new StringGoogleDataColumn(column);
                case "System.UInt16": return new NumberGoogleDataColumn(column);
                case "System.UInt32": return new NumberGoogleDataColumn(column);
                case "System.UInt64": return new NumberGoogleDataColumn(column);
                default: return new StringGoogleDataColumn(column);
            }
        }
开发者ID:JulsMan,项目名称:googlevisualizationsdotnet,代码行数:37,代码来源:GoogleDataColumn.cs

示例11: SourceForm

        public SourceForm()
        {
            InitializeComponent();
            LiterarySources = new DataTable();
            var column = new DataColumn()
            {
                Caption = "Literary Source",
                ColumnName = "LiterarySource",
                ReadOnly = true,
                DataType = typeof (string)
            };
            LiterarySources.Columns.Add(column);
            column = new DataColumn()
            {
                Caption = "Description",
                ColumnName = "GetDescription",
                ReadOnly = true,
                DataType = typeof (string)
            };
            LiterarySources.Columns.Add(column);
            SourceDataGridView.DataSource = LiterarySources;
            SourceDataGridView.Columns[0].Width = 120;
            SourceDataGridView.Columns[1].Width = 225;

            SourceDataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            sourcesList = new List<IReferences>();
        }
开发者ID:nespec93,项目名称:NewRepozitoty,代码行数:27,代码来源:Form1.cs

示例12: CarregarPesquisaTitulos

        public void CarregarPesquisaTitulos(string conteudo)
        {
            DataTable dt = new DataTable();
            DataColumn coluna1 = new DataColumn("ID", Type.GetType("System.Int32"));
            DataColumn coluna2 = new DataColumn("CODIGO", Type.GetType("System.String"));
            DataColumn coluna3 = new DataColumn("DESCRICAO", Type.GetType("System.String"));

            dt.Columns.Add(coluna1);
            dt.Columns.Add(coluna2);
            dt.Columns.Add(coluna3);

            TitulosBL titBL = new TitulosBL();
            Titulos tit = new Titulos();
            List<Titulos> titulos = titBL.PesquisarBuscaBL("R",conteudo);

            foreach (Titulos ltTit in titulos)
            {
                DataRow linha = dt.NewRow();

                linha["ID"] = ltTit.Id;
                linha["CODIGO"] = ltTit.Numero;
                linha["DESCRICAO"] = ltTit.Parcela;

                dt.Rows.Add(linha);
            }

            grdPesquisatit.DataSource = dt;
            grdPesquisatit.DataBind();
        }
开发者ID:Letractively,项目名称:casa-espirita,代码行数:29,代码来源:emissaoBloqBan.aspx.cs

示例13: CarregarPesquisa

        public void CarregarPesquisa(string conteudo)
        {
            DataTable dt = new DataTable();
            DataColumn coluna1 = new DataColumn("ID", Type.GetType("System.Int32"));
            DataColumn coluna2 = new DataColumn("CODIGO", Type.GetType("System.String"));
            DataColumn coluna3 = new DataColumn("DESCRICAO", Type.GetType("System.String"));

            dt.Columns.Add(coluna1);
            dt.Columns.Add(coluna2);
            dt.Columns.Add(coluna3);

            PessoasBL pesBL = new PessoasBL();
            Pessoas pe = new Pessoas();
            List<Pessoas> pessoas = pesBL.PesquisarBuscaBL(conteudo);

            foreach (Pessoas pes in pessoas)
            {
                DataRow linha = dt.NewRow();

                linha["ID"] = pes.Id;
                linha["CODIGO"] = pes.Codigo;
                linha["DESCRICAO"] = pes.Nome;

                dt.Rows.Add(linha);
            }

            grdPesquisa.DataSource = dt;
            grdPesquisa.DataBind();
        }
开发者ID:Letractively,项目名称:casa-espirita,代码行数:29,代码来源:emissaoBloqBan.aspx.cs

示例14: Form1_Load

        private void Form1_Load(object sender, EventArgs e)
        {
            //Create a DataSet from the XML file
            string filePath = "..\\..\\Employees.xml";
            DataSet ds = new DataSet();
            ds.ReadXml(filePath);

            //Create and add barcode column
            DataColumn dc = new DataColumn("BarcodeImage", typeof(byte[]));
            ds.Tables[0].Columns.Add(dc);

            //We'll use Code 128 Barcode Symbology
            BaseBarcode b = BarcodeFactory.GetBarcode(Symbology.Code128);

            b.Height = 50;
            b.FontHeight = 0.3F;
            //Now, generate and fill barcode images
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                //We'll encode the ID column
                b.Number = (string)dr["ID"];

                //Create bitmap and save it to BarcodeImage column
                MemoryStream ms = new MemoryStream();
                b.Save(ms, ImageType.Png);
                dr["BarcodeImage"] = ms.GetBuffer();
            }

            CrystalReport1 report = new CrystalReport1();
            report.SetDataSource(ds);
            crystalReportViewer1.ReportSource = report;
        }
开发者ID:BGCX261,项目名称:zlap-svn-to-git,代码行数:32,代码来源:Form1.cs

示例15: run

	//Activate This Construntor to log All To Standard output
	//public TestClass():base(true){}

	//Activate this constructor to log Failures to a log file
	//public TestClass(System.IO.TextWriter tw):base(tw, false){}


	//Activate this constructor to log All to a log file
	//public TestClass(System.IO.TextWriter tw):base(tw, true){}

	//BY DEFAULT LOGGING IS DONE TO THE STANDARD OUTPUT ONLY FOR FAILURES

	public void run()
	{
		Exception exp = null;

		DataTable dt = new DataTable(); 
		DataColumn dc0 = new DataColumn("Col0",typeof(int));
		DataColumn dc1 = new DataColumn("Col1",typeof(int));
		dt.Columns.Add(dc0);
		dt.Columns.Add(dc1);
		dt.Rows.Add(new object[] {1234});
		DataRow dr = dt.Rows[0];
            		
		try
		{
			BeginCase("IsNull_I 2");
			Compare(dr.IsNull(0) ,false );
		}
		catch(Exception ex)	{exp = ex;}
		finally	{EndCase(exp); exp = null;}
	

		try
		{
			BeginCase("IsNull_I 2");
			Compare(dr.IsNull(1) ,true );
		}
		catch(Exception ex)	{exp = ex;}
		finally	{EndCase(exp); exp = null;}
	
	}
开发者ID:nlhepler,项目名称:mono,代码行数:42,代码来源:DataRow_IsNull_I.cs


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