CSharpTest.Net
GetString(String) Method
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Data Namespace > CsvReader Class > GetString Method : GetString(String) Method

name

Glossary Item Box

Gets the string value of the specified field.

Syntax

Visual Basic (Declaration) 
Public Overloads Function GetString( _
   ByVal name As String _
) As String
C# 
public string GetString( 
   string name
)

Parameters

name

Example

Library/Library.Test/TestCsvReader.cs

C#Copy Code
using (CsvReader r = new CsvReader(new StringReader(CSV_DOC1)))
{
    Assert.AreEqual(0, r.Depth);
    Assert.IsFalse(r.IsClosed);
    Assert.AreEqual(3, r.FieldCount);
    Assert.IsTrue(r.Read());
    Assert.AreEqual(3, r.FieldCount);
    Assert.IsTrue(r.Read());
    
    //second row has an extra field
    Assert.AreEqual(4, r.FieldCount);
    Assert.AreEqual("3", r.GetName(3));
    Assert.AreEqual(3, r.GetOrdinal("3"));
    Assert.AreEqual("extra", r.GetValue(3));

    Assert.IsTrue(r.Read());
    Assert.IsFalse(r.IsDBNull(0));
    Assert.AreEqual("3a", r.GetString("f1"));
    Assert.IsTrue(r.IsDBNull(1));
    Assert.IsTrue(r.IsDBNull(2));

    Assert.IsTrue(r.Read());
    Assert.IsTrue(r.Read());
    Assert.IsFalse(r.Read());
}
VB.NETCopy Code
Using r As New CsvReader(New StringReader(CSV_DOC1))
    Assert.AreEqual(0, r.Depth)
    Assert.IsFalse(r.IsClosed)
    Assert.AreEqual(3, r.FieldCount)
    Assert.IsTrue(r.Read())
    Assert.AreEqual(3, r.FieldCount)
    Assert.IsTrue(r.Read())

    'second row has an extra field
    Assert.AreEqual(4, r.FieldCount)
    Assert.AreEqual("3", r.GetName(3))
    Assert.AreEqual(3, r.GetOrdinal("3"))
    Assert.AreEqual("extra", r.GetValue(3))

    Assert.IsTrue(r.Read())
    Assert.IsFalse(r.IsDBNull(0))
    Assert.AreEqual("3a", r.GetString("f1"))
    Assert.IsTrue(r.IsDBNull(1))
    Assert.IsTrue(r.IsDBNull(2))

    Assert.IsTrue(r.Read())
    Assert.IsTrue(r.Read())
    Assert.IsFalse(r.Read())
End Using

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys