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


C# SqlDataReader.GetChars方法代码示例

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


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

示例1: GetChars

		public void GetChars ()
		{
			cmd.CommandText = "Select type_char, type_varchar,type_text, type_ntext ";
			cmd.CommandText += "from string_family where id=1";
			reader = cmd.ExecuteReader ();
			reader.Read ();
			string charstring = reader.GetString (0);
			//string ncharstring = reader.GetString (1);
			string varcharstring = reader.GetString (1);
			//string nvarcharstring = reader.GetString (2);
			string textstring = reader.GetString (2);
			string ntextstring = reader.GetString (3);
			reader.Close ();
			
			reader = cmd.ExecuteReader (CommandBehavior.SequentialAccess);
			reader.Read ();
			int len = 0;
			char[] arr; 

			len = (int) reader.GetChars (0, 0, null, 0, 0);
			Assert.AreEqual (charstring.Length, len, "#1");
			arr = new char [len];
			reader.GetChars (0, 0, arr, 0, len);
			Assert.AreEqual (0, charstring.CompareTo (new String (arr)), "#2");

			len = (int)reader.GetChars (1,0,null,0,0);
			Assert.AreEqual (varcharstring.Length, len, "#3");
			arr = new char [len];
			reader.GetChars (1, 0,arr,0,len);
			Assert.AreEqual (0, varcharstring.CompareTo (new String (arr)), "#4");

			len = (int)reader.GetChars (2,0,null,0,0);
			Assert.AreEqual (textstring.Length, len, "#5");
			arr = new char [len];
			reader.GetChars (2,0,arr,0,len);
			Assert.AreEqual (0, textstring.CompareTo (new String (arr)), "#6");

			len = (int)reader.GetChars (3,0,null,0,0);
			Assert.AreEqual (ntextstring.Length, len, "#7");
			arr = new char [len];
			reader.GetChars (3,0,arr,0,len);
			Assert.AreEqual (0, ntextstring.CompareTo (new String (arr)), "#8");

			reader.Close ();

			reader = cmd.ExecuteReader (CommandBehavior.SequentialAccess);
			reader.Read ();
			
			len  = (int)reader.GetChars (0,0,null,0,0);
			arr = new char [10];
			for (int i = 0; i < len; ++i) {
				Assert.AreEqual (len - i, reader.GetChars (0, i, null, 0, 0), "#9_" + i);
				Assert.AreEqual (1, reader.GetChars (0, i, arr, 0, 1), "#10_" + i);
				Assert.AreEqual (charstring [i], arr [0], "#11_" + i);
			}
			Assert.AreEqual (0, reader.GetChars (0, len + 10, null, 0, 0));

			reader.Close ();
		}
开发者ID:Profit0004,项目名称:mono,代码行数:59,代码来源:SqlDataReaderTest.cs

示例2: GetBufferFor

 private StringBuffer GetBufferFor( SqlDataReader reader, int ordinal )
 {
     var length = reader.GetChars( ordinal,0,null,0,0 );
        var bufferBlock =(int) length / bufferStep;
        Stack<char[]> buffers;
        lock( _reservedBuffers )
        {
        if( !_reservedBuffers.TryGetValue( bufferBlock,out buffers ) )
        {
            buffers = new Stack<char[]>();
            _reservedBuffers.Add( bufferBlock, buffers );
        }
        }
        char[] buffer;
        lock( buffers )
        {
        buffer = buffers.Count!=0
            ? buffers.Pop()
            : new char[(bufferBlock+1)*bufferStep];
        }
        reader.GetChars( ordinal,0,buffer,0,(int)length );
        return new StringBuffer() {
        length = (int) length,
        buffer = buffer };
 }
开发者ID:kazuk,项目名称:T4Adonet,代码行数:25,代码来源:SelectCommandGenerator.cs


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