本文整理汇总了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 ();
}
示例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 };
}