次の方法で共有


DataTable.CaseSensitive プロパティ

テーブル内の文字列比較で大文字と小文字を区別するかどうかを示します。

Public Property CaseSensitive As Boolean
[C#]
public bool CaseSensitive {get; set;}
[C++]
public: __property bool get_CaseSensitive();public: __property void set_CaseSensitive(bool);
[JScript]
public function get CaseSensitive() : Boolean;public function set CaseSensitive(Boolean);

プロパティ値

比較で大文字と小文字を区別する場合は true 。それ以外の場合は false 。既定値は親 DataSet オブジェクトの CaseSensitive プロパティに設定します。 DataSet とは独立して DataTable を作成した場合は false に設定します。

解説

CaseSensitive プロパティは、並べ替え、検索、およびフィルタ処理での文字列比較に影響を与えます。

使用例

[Visual Basic, C#, C++] DataTableSelect メソッドを 2 回呼び出す例を次に示します。最初の呼び出しで CaseSensitive プロパティを true に設定し、2 回目の呼び出しで false に設定します。

 

Private Sub ToggleCaseSensitive()
    Dim t As DataTable
    Dim foundRows() As DataRow

    t = CreateDataSet().Tables(0)
    
    t.CaseSensitive = False
    Console.WriteLine("CaseSensitive = False")

    ' Presuming the DataTable has a column named 'id'
    foundRows = t.Select("id = 'abc'")

    Dim i As Integer
    ' Print out DataRow values. Presumes row 0 contains the value we're looking for.
    For i = 0 To foundRows.GetUpperBound(0)
      Console.WriteLine(foundRows(0)(0))
    Next
 
    Console.WriteLine("CaseSensitive = True")
    t.CaseSensitive = True
    foundRows = t.Select("id = 'abc'")
 
    For i = 0 To foundRows.GetUpperBound(0)
      Console.WriteLine(foundRows(0)(0))
    Next
End Sub

Public Function CreateDataSet() As DataSet
     ' Create a DataSet with one table, two columns
     Dim ds As New DataSet
     Dim t As New DataTable("Items")

     ' Add table to DataSet
     ds.Tables.Add(t)

     ' Add two columns
     Dim c As DataColumn

     ' First column
     c = t.Columns.Add("id", Type.GetType("System.Int32"))
     c.AutoIncrement = True

     ' Second column
     t.Columns.Add("item", Type.GetType("System.String"))

     ' Set primary key
     Dim newKey(1) as DataColumn
     newKey(1) = t.Columns("id")
     t.PrimaryKey = newKey

     ' Add twelve rows
     Dim r As DataRow
     Dim i as Integer

     For i = 1 to 10
          r = t.NewRow()
          r(i) = i.ToString()
          t.Rows.Add(r)
     Next i

     r = t.NewRow()
     r(11) = "abc"
     t.Rows.Add(r)

     r = t.NewRow()
     r(15) = "ABC"
     t.Rows.Add(r)

     CreateDataSet = ds
End Function


[C#] 
private static void ToggleCaseSensitive()
{
    DataTable t;
    DataRow[] foundRows; 
    
    t = CreateDataSet().Tables[0];

    t.CaseSensitive = false;
    // Presuming the DataTable has a column named 'id'.
    foundRows = t.Select("item = 'abc'");

    // Print out DataRow values. Presumes row 0 contains the value we're looking for.
    PrintRowValues( foundRows, "CaseSensitive = False" );

    t.CaseSensitive = true;
    foundRows = t.Select("item = 'abc'");

    PrintRowValues( foundRows, "CaseSensitive = True" );
}

public static DataSet CreateDataSet()
{
    // Create a DataSet with one table, two columns
    DataSet ds = new DataSet();
    DataTable t = new DataTable( "Items" );

    // Add table to dataset
    ds.Tables.Add( t );

    // Add two columns
    DataColumn c;

    // First column
    c = t.Columns.Add( "id", typeof(int) );
    c.AutoIncrement = true;

    // Second column
    t.Columns.Add( "item", typeof(string) );

    // Set primary key
    t.PrimaryKey = new DataColumn[] { t.Columns["id"] };

    // Add twelve rows
    for( int i=0; i<10; i++ )
    {
        t.Rows.Add( new object[] { i, i } );
    }
    t.Rows.Add( new object[] { 11, "abc" } );
    t.Rows.Add( new object[] { 15, "ABC" } );

    return ds;
}

private static void PrintRowValues( DataRow[] rows, string label )
{
    Console.WriteLine();
    Console.WriteLine( "{0}\n", label );
    if( rows.Length <= 0 )
    {
        Console.WriteLine( "no rows found" );
        return;
    }
    foreach( DataRow r in rows )
    {
        foreach( DataColumn c in r.Table.Columns )
        {
            Console.Write( "\t {0}", r[c] );
        }
        Console.WriteLine();
    }
}

[C++] 
private:
static void ToggleCaseSensitive()
{
    DataTable* t;
    DataRow* foundRows[]; 
    
    t = CreateDataSet()->Tables->Item[0];

    t->CaseSensitive = false;
    // Presuming the DataTable has a column named 'id'.
    foundRows = t->Select(S"item = 'abc'");

    // Print out DataRow values. Presumes row 0 contains the value we're looking for.
    PrintRowValues( foundRows, S"CaseSensitive = False" );

    t->CaseSensitive = true;
    foundRows = t->Select(S"item = 'abc'");

    PrintRowValues( foundRows, S"CaseSensitive = True" );
}

public:
static DataSet* CreateDataSet()
{
    // Create a DataSet with one table, two columns
    DataSet* ds = new DataSet();
    DataTable* t = new DataTable( S"Items" );

    // Add table to dataset
    ds->Tables->Add( t );

    // Add two columns
    DataColumn* c;

    // First column
    c = t->Columns->Add( S"id", __typeof(int) );
    c->AutoIncrement = true;

    // Second column
    t->Columns->Add( S"item", __typeof(String) );

    // Set primary key

    DataColumn* temp4 [] = {t->Columns->Item[S"id"]};
    t->PrimaryKey = temp4;

    // Add twelve rows
    for( int i=0; i<10; i++ )
    {

        Object* temp0 [] = {__box(i), __box(i)};
        t->Rows->Add( temp0 );
    }

    Object* temp1 [] = {__box(11), S"abc"};
    t->Rows->Add( temp1 );

    Object* temp2 [] = {__box(15), S"ABC"};
    t->Rows->Add( temp2 );

    return ds;
}

private:
static void PrintRowValues( DataRow* rows[], String* label )
{
    Console::WriteLine();
    Console::WriteLine( S"{0}\n", label );
    if( rows->Length <= 0 )
    {
        Console::WriteLine( S"no rows found" );
        return;
    }
    System::Collections::IEnumerator* myEnum = rows->GetEnumerator();
    while (myEnum->MoveNext())
    {
        DataRow* r = __try_cast<DataRow*>(myEnum->Current);
        System::Collections::IEnumerator* myEnum1 = r->Table->Columns->GetEnumerator();
        while (myEnum1->MoveNext())
        {
            DataColumn* c = __try_cast<DataColumn*>(myEnum1->Current);
            Console::Write( S"\t {0}", r->Item[c] );
        }
        Console::WriteLine();
    }
}

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET

参照

DataTable クラス | DataTable メンバ | System.Data 名前空間 | Select