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


C# DataColumn.ToString方法代码示例

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


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

示例1: Add

	        public void Add ()
		{
			DataTable Table = new DataTable ("test_table");
			DataColumnCollection Cols = Table.Columns;
			DataColumn C = null;
			Cols.Add ();
			Cols.Add ();
	        	
	        	C = Cols [0];
			Assert.IsTrue (C.AllowDBNull, "test#01");
			Assert.IsFalse (C.AutoIncrement, "test#02");
			Assert.AreEqual (0L, C.AutoIncrementSeed, "test#03");
			Assert.AreEqual (1L, C.AutoIncrementStep, "test#04");
			Assert.AreEqual ("Column1", C.Caption, "test#05");
			Assert.AreEqual ("Element", C.ColumnMapping.ToString (), "test#06");
			Assert.AreEqual ("Column1", C.ColumnName, "test#07");
			Assert.IsNull (C.Container, "test#08");
			Assert.AreEqual (typeof (string), C.DataType, "test#09");
			Assert.AreEqual (DBNull.Value, C.DefaultValue, "test#10");
			Assert.IsFalse (C.DesignMode, "test#11");
			Assert.AreEqual ("", C.Expression, "test#12");
			Assert.AreEqual (0, C.ExtendedProperties.Count, "test#13");
			Assert.AreEqual (-1, C.MaxLength, "test#14");
			Assert.AreEqual ("", C.Namespace, "test#15");
			Assert.AreEqual (0, C.Ordinal, "test#16");
			Assert.AreEqual ("", C.Prefix, "test#17");
			Assert.IsFalse (C.ReadOnly, "test#18");
			Assert.IsNull (C.Site, "test#19");
			Assert.AreEqual ("test_table", C.Table.TableName, "test#20");
			Assert.AreEqual ("Column1", C.ToString (), "test#21");
			Assert.IsFalse (C.Unique, "test#22");

			C = Cols [1];
			Assert.IsTrue (C.AllowDBNull, "test#23");
			Assert.IsFalse (C.AutoIncrement, "test#24");
			Assert.AreEqual (0L, C.AutoIncrementSeed, "test#25");
			Assert.AreEqual (1L, C.AutoIncrementStep, "test#26");
			Assert.AreEqual ("Column2", C.Caption, "test#27");
			Assert.AreEqual ("Element", C.ColumnMapping.ToString (), "test#28");
			Assert.AreEqual ("Column2", C.ColumnName, "test#29");
			Assert.IsNull (C.Container, "test#30");
			Assert.AreEqual (typeof (string), C.DataType, "test#31");
			Assert.AreEqual (DBNull.Value, C.DefaultValue, "test#32");
			Assert.IsFalse (C.DesignMode, "test#33");
			Assert.AreEqual ("", C.Expression, "test#34");
			Assert.AreEqual (0, C.ExtendedProperties.Count, "test#35");
			Assert.AreEqual (-1, C.MaxLength, "test#36");
			Assert.AreEqual ("", C.Namespace, "test#37");
			Assert.AreEqual (1, C.Ordinal, "test#38");
			Assert.AreEqual ("", C.Prefix, "test#39");
			Assert.IsFalse (C.ReadOnly, "test#40");
			Assert.IsNull (C.Site, "test#41");
			Assert.AreEqual ("test_table", C.Table.TableName, "test#42");
			Assert.AreEqual ("Column2", C.ToString (), "test#43");
			Assert.IsFalse (C.Unique, "test#44");

			Cols.Add ("test1", typeof (int), "");
			Cols.Add ("test2", typeof (string), "Column1 + Column2");

			C = Cols [2];
			Assert.IsTrue (C.AllowDBNull, "test#45");
			Assert.IsFalse (C.AutoIncrement, "test#46");
			Assert.AreEqual (0L, C.AutoIncrementSeed, "test#47");
			Assert.AreEqual (1L, C.AutoIncrementStep, "test#48");
			Assert.AreEqual ("test1", C.Caption, "test#49");
			Assert.AreEqual ("Element", C.ColumnMapping.ToString (), "test#50");
			Assert.AreEqual ("test1", C.ColumnName, "test#51");
			Assert.IsNull (C.Container, "test#52");
			Assert.AreEqual (typeof (int), C.DataType, "test#53");
			Assert.AreEqual (DBNull.Value, C.DefaultValue, "test#54");
			Assert.IsFalse (C.DesignMode, "test#55");
			Assert.AreEqual ("", C.Expression, "test#56");
			Assert.AreEqual (0, C.ExtendedProperties.Count, "test#57");
			Assert.AreEqual (-1, C.MaxLength, "test#58");
			Assert.AreEqual ("", C.Namespace, "test#59");
			Assert.AreEqual (2, C.Ordinal, "test#60");
			Assert.AreEqual ("", C.Prefix, "test#61");
			Assert.IsFalse (C.ReadOnly, "test#62");
			Assert.IsNull (C.Site, "test#63");
			Assert.AreEqual ("test_table", C.Table.TableName, "test#64");
			Assert.AreEqual ("test1", C.ToString (), "test#65");
			Assert.IsFalse (C.Unique, "test#66");

			C = Cols [3];
			Assert.IsTrue (C.AllowDBNull, "test#67");
			Assert.IsFalse (C.AutoIncrement, "test#68");
			Assert.AreEqual (0L, C.AutoIncrementSeed, "test#69");
			Assert.AreEqual (1L, C.AutoIncrementStep, "test#70");
			Assert.AreEqual ("test2", C.Caption, "test#71");
			Assert.AreEqual ("Element", C.ColumnMapping.ToString (), "test#72");
			Assert.AreEqual ("test2", C.ColumnName, "test#73");
			Assert.IsNull (C.Container, "test#74");
			Assert.AreEqual (typeof (string), C.DataType, "test#75");
			Assert.AreEqual (DBNull.Value, C.DefaultValue, "test#76");
			Assert.IsFalse (C.DesignMode, "test#77");
			Assert.AreEqual ("Column1 + Column2", C.Expression, "test#78");
			Assert.AreEqual (0, C.ExtendedProperties.Count, "test#79");
			Assert.AreEqual (-1, C.MaxLength, "test#80");
			Assert.AreEqual ("", C.Namespace, "test#81");
			Assert.AreEqual (3, C.Ordinal, "test#82");
//.........这里部分代码省略.........
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:101,代码来源:DataColumnCollectionTest.cs

示例2: TestToString

		[Test] public void TestToString()
		{
			DataColumn dc;
			string sColName,sExp;
			dc = new DataColumn();

			//ToString = ""
			//Console.WriteLine(dc.ToString());

			//ToString = ColumnName 			
			sColName = "Test1";
			dc.ColumnName = sColName;
				// ToString - ColumnName
				Assert.AreEqual(sColName , dc.ToString() , "DC42");

			//TosTring = ColumnName + " + " + Expression
			sExp = "Tax * 1.234";
			dc.Expression = sExp;
				// TosTring=ColumnName + Expression
				Assert.AreEqual(sColName + " + " + sExp , dc.ToString() , "DC43");
		}
开发者ID:wamiq,项目名称:debian-mono,代码行数:21,代码来源:DataColumnTest2.cs

示例3: AddRange

		public void AddRange ()
		{			
			DataTable Table = new DataTable ("test_table");
			DataTable Table2 = new DataTable ("test_table2");
			DataColumnCollection Cols = Table.Columns;
			DataColumn C = null;
			DataColumn [] ColArray = new DataColumn [2];

			C = new DataColumn ("test1");
			ColArray [0] = C;

			C = new DataColumn ("test2");
			C.AllowDBNull = false;
			C.Caption = "Test_caption";
			C.DataType = typeof (XmlReader);
			ColArray [1] = C;

			Cols.AddRange (ColArray);

			C = Cols [0];
			Assert.IsTrue (C.AllowDBNull, "test#01");
			Assert.IsFalse (C.AutoIncrement, "test#02");
			Assert.AreEqual (0L, C.AutoIncrementSeed, "test#03");
			Assert.AreEqual (1L, C.AutoIncrementStep, "test#04");
			Assert.AreEqual ("test1", C.Caption, "test#05");
			Assert.AreEqual ("Element", C.ColumnMapping.ToString (), "test#06");
			Assert.AreEqual ("test1", C.ColumnName, "test#07");
			Assert.IsNull (C.Container, "test#08");
			Assert.AreEqual (typeof (string), C.DataType, "test#09");
			Assert.AreEqual (DBNull.Value, C.DefaultValue, "test#10");
			Assert.IsFalse (C.DesignMode, "test#11");
			Assert.AreEqual ("", C.Expression, "test#12");
			Assert.AreEqual (0, C.ExtendedProperties.Count, "test#13");
			Assert.AreEqual (-1, C.MaxLength, "test#14");
			Assert.AreEqual ("", C.Namespace, "test#15");
			Assert.AreEqual (0, C.Ordinal, "test#16");
			Assert.AreEqual ("", C.Prefix, "test#17");
			Assert.IsFalse (C.ReadOnly, "test#18");
			Assert.IsNull (C.Site, "test#19");
			Assert.AreEqual ("test_table", C.Table.TableName, "test#20");
			Assert.AreEqual ("test1", C.ToString (), "test#21");
			Assert.IsFalse (C.Unique, "test#22");

			C = Cols [1];
			Assert.IsFalse (C.AllowDBNull, "test#01");
			Assert.IsFalse (C.AutoIncrement, "test#02");
			Assert.AreEqual (0L, C.AutoIncrementSeed, "test#03");
			Assert.AreEqual (1L, C.AutoIncrementStep, "test#04");
			Assert.AreEqual ("Test_caption", C.Caption, "test#05");
			Assert.AreEqual ("Element", C.ColumnMapping.ToString (), "test#06");
			Assert.AreEqual ("test2", C.ColumnName, "test#07");
			Assert.IsNull (C.Container, "test#08");
			Assert.AreEqual (typeof (XmlReader), C.DataType, "test#09");
			Assert.AreEqual (DBNull.Value, C.DefaultValue, "test#10");
			Assert.IsFalse (C.DesignMode, "test#11");
			Assert.AreEqual ("", C.Expression, "test#12");
			Assert.AreEqual (0, C.ExtendedProperties.Count, "test#13");
			Assert.AreEqual (-1, C.MaxLength, "test#14");
			Assert.AreEqual ("", C.Namespace, "test#15");
			Assert.AreEqual (1, C.Ordinal, "test#16");
			Assert.AreEqual ("", C.Prefix, "test#17");
			Assert.IsFalse (C.ReadOnly, "test#18");
			Assert.IsNull (C.Site, "test#19");
			Assert.AreEqual ("test_table", C.Table.TableName, "test#20");
			Assert.AreEqual ("test2", C.ToString (), "test#21");
			Assert.IsFalse (C.Unique, "test#22");
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:67,代码来源:DataColumnCollectionTest.cs

示例4: OpenCSV

        /// <summary>
        /// 将CSV文件的数据读取到DataTable中
        /// </summary>
        /// <param name="fileName">CSV文件路径</param>
        /// <returns>返回读取了CSV数据的DataTable</returns>
        public DataTable OpenCSV(string filePath)
        {
            //Encoding encoding = Common.GetType(filePath); //Encoding.ASCII;//

            DataTable dt = new DataTable();
            FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);

            StreamReader sr = new StreamReader(fs);
            //记录每次读取的一行记录
            string strLine = "";
            //记录每行记录中的各字段内容
            string[] aryLine = null;
            string[] tableHead = null;
            //标示列数
            int columnCount = 0;
            //标示是否是读取的第一行
            bool IsFirst = true;
            //逐行读取CSV中的数据
            while ((strLine = sr.ReadLine()) != null)
            {

                if (IsFirst == true)
                {
                    tableHead = strLine.Split(',');
                    IsFirst = false;
                    columnCount = tableHead.Length;
                    //创建列
                    for (int i = 0; i < columnCount; i++)
                    {
                        //格式转换
                        switch (i)
                        {
                            case 0:
                                DataColumn dc0 = new DataColumn(tableHead[i]);
                                dt.Columns.Add(dc0.ToString(), typeof(string));
                                break;
                            case 5:
                                DataColumn dc1 = new DataColumn(tableHead[i]);
                                dt.Columns.Add(dc1.ToString(), typeof(int));
                                break;
                            case 1:
                            case 2:
                            case 3:
                            case 4:
                            case 6:
                                DataColumn dc2 = new DataColumn(tableHead[i]);
                                dt.Columns.Add(dc2.ToString(), typeof(float));
                                break;
                            default:
                                break;
                        }
                    }
                }
                else
                {
                    aryLine = strLine.Split(',');
                    DataRow dr = dt.NewRow();
                    for (int j = 0; j < columnCount; j++)
                    {
                        //格式转换
                        switch (j)
                        {
                            case 0:
                                aryLine[j] = aryLine[j].Replace("-", "");//去除日期串中的‘-’
                                dr[j] = int.Parse(aryLine[j]);//转整型
                                break;
                            case 5:
                                dr[j] = int.Parse(aryLine[j]);
                                break;
                            case 1:
                            case 2:
                            case 3:
                            case 4:
                            case 6:
                                dr[j] = float.Parse(aryLine[j]);
                                break;
                            default:
                                break;
                        }
                        dr[j] = aryLine[j];
                    }
                    dt.Rows.Add(dr);
                }
            }
            if (aryLine != null && aryLine.Length > 0)
            {
                dt.DefaultView.Sort = tableHead[0] + " " + "desc";  //第一列倒排
            }

            sr.Close();
            fs.Close();
            return dt;
        }
开发者ID:godsonhyl,项目名称:MarketInfo,代码行数:98,代码来源:GeneralClass.cs

示例5: 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;
	
		DataColumn dc;
		string sColName,sExp;
		dc = new DataColumn();
			
		//ToString = ""
		//Console.WriteLine(dc.ToString());
			
		//ToString = ColumnName 			
		sColName = "Test1";
		dc.ColumnName = sColName;
		try
		{
			BeginCase("ToString - ColumnName");
			Compare(dc.ToString() ,sColName );
		}
		catch(Exception ex)	{exp = ex;}
		finally	{EndCase(exp); exp = null;}
					
		//TosTring = ColumnName + " + " + Expression
		sExp = "Tax * 1.234";
		dc.Expression = sExp;
		try
		{
			BeginCase("TosTring=ColumnName + Expression");
			Compare(dc.ToString() ,sColName + " + " + sExp );
		}
		catch(Exception ex)	{exp = ex;}
		finally	{EndCase(exp); exp = null;}
		

	}
开发者ID:nlhepler,项目名称:mono,代码行数:47,代码来源:DataColumn_ToString.cs

示例6: AddRange

		public void AddRange ()
		{			
			DataTable Table = new DataTable ("test_table");
			DataTable Table2 = new DataTable ("test_table2");
			DataColumnCollection Cols = Table.Columns;
			DataColumn C = null;
			DataColumn [] ColArray = new DataColumn [2];

			C = new DataColumn ("test1");
			ColArray [0] = C;

			C = new DataColumn ("test2");
			C.AllowDBNull = false;
			C.Caption = "Test_caption";
			C.DataType = typeof (XmlReader);
			ColArray [1] = C;

			Cols.AddRange (ColArray);

			C = Cols [0];
			AssertEquals ("test#01", true, C.AllowDBNull);
			AssertEquals ("test#02", false, C.AutoIncrement);
			AssertEquals ("test#03", 0L, C.AutoIncrementSeed);
			AssertEquals ("test#04", 1L, C.AutoIncrementStep);
			AssertEquals ("test#05", "test1", C.Caption);
			AssertEquals ("test#06", "Element", C.ColumnMapping.ToString ());
			AssertEquals ("test#07", "test1", C.ColumnName);
			AssertEquals ("test#08", true, C.Container == null);
			AssertEquals ("test#09", typeof (string), C.DataType);
			AssertEquals ("test#10", DBNull.Value, C.DefaultValue);
			AssertEquals ("test#11", false, C.DesignMode);
			AssertEquals ("test#12", "", C.Expression);
			AssertEquals ("test#13", 0, C.ExtendedProperties.Count);
			AssertEquals ("test#14", -1, C.MaxLength);
			AssertEquals ("test#15", "", C.Namespace);
			AssertEquals ("test#16", 0, C.Ordinal);
			AssertEquals ("test#17", "", C.Prefix);
			AssertEquals ("test#18", false, C.ReadOnly);
			AssertEquals ("test#19", null, C.Site);
			AssertEquals ("test#20", "test_table", C.Table.TableName);
			AssertEquals ("test#21", "test1", C.ToString ());
			AssertEquals ("test#22", false, C.Unique);

			C = Cols [1];
			AssertEquals ("test#01", false, C.AllowDBNull);
			AssertEquals ("test#02", false, C.AutoIncrement);
			AssertEquals ("test#03", 0L, C.AutoIncrementSeed);
			AssertEquals ("test#04", 1L, C.AutoIncrementStep);
			AssertEquals ("test#05", "Test_caption", C.Caption);
			AssertEquals ("test#06", "Element", C.ColumnMapping.ToString ());
			AssertEquals ("test#07", "test2", C.ColumnName);
			AssertEquals ("test#08", true, C.Container == null);
			AssertEquals ("test#09", typeof (XmlReader), C.DataType);
			AssertEquals ("test#10", DBNull.Value, C.DefaultValue);
			AssertEquals ("test#11", false, C.DesignMode);
			AssertEquals ("test#12", "", C.Expression);
			AssertEquals ("test#13", 0, C.ExtendedProperties.Count);
			AssertEquals ("test#14", -1, C.MaxLength);
			AssertEquals ("test#15", "", C.Namespace);
			AssertEquals ("test#16", 1, C.Ordinal);
			AssertEquals ("test#17", "", C.Prefix);
			AssertEquals ("test#18", false, C.ReadOnly);
			AssertEquals ("test#19", null, C.Site);
			AssertEquals ("test#20", "test_table", C.Table.TableName);
			AssertEquals ("test#21", "test2", C.ToString ());
			AssertEquals ("test#22", false, C.Unique);
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:67,代码来源:DataColumnCollectionTest.cs

示例7: GetBoundControlForColumn

        /// <summary>
        /// Returns the Control that is bound to the specified DataColumn.
        ///
        /// </summary>
        /// <param name="ABindingManagerBase">A BindingManagerBase. Such an Object can be
        /// retrieved e.g. by such a code: BindingContext[FMainDS.PPartner]</param>
        /// <param name="AColumn">The DataColumn to which the Control should be found</param>
        /// <returns>The Control, if it could be found, otherwise nil.
        /// </returns>
        public static Control GetBoundControlForColumn(BindingManagerBase ABindingManagerBase, DataColumn AColumn)
        {
            int Counter;

            // MessageBox.Show('ABindingManagerBase.Bindings.Count: ' + ABindingManagerBase.Bindings.Count.ToSTring);
            for (Counter = 0; Counter <= ABindingManagerBase.Bindings.Count - 1; Counter += 1)
            {
                // MessageBox.Show('Bound Control # ' + Counter.ToString + ': ' + ABindingManagerBase.Bindings[Counter].Control.ToString + '; bound to field: ' + ABindingManagerBase.Bindings[Counter].BindingMemberInfo.BindingField.ToString);
                if (ABindingManagerBase.Bindings[Counter].BindingMemberInfo.BindingField == AColumn.ToString())
                {
                    return ABindingManagerBase.Bindings[Counter].Control;
                }
            }

            return null;
        }
开发者ID:Davincier,项目名称:openpetra,代码行数:25,代码来源:DataBinding.cs


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