Get a table (C#)

Tables with the Data API are currently in public preview. Development is ongoing, and the features and functionality are subject to change. Hyper-Converged Database (HCD), and the use of such, is subject to the DataStax Preview Terms.

Gets a reference to a table for use with the Data API clients.

Ready to write code? See the examples for this method to get started. If you are new to the Data API, check out the quickstart.

Result

Returns a Table object that corresponds to the specified table name.

This method returns a Table object even for tables that don’t exist.

By default, the Table object is typed as Table<Row>, where Row is Dictionary<string, object>. You can enable stronger typing by specifying a type when you get the table. For more information and examples, see Custom typing for tables.

Parameters

Use the GetTable method, which belongs to the Database class.

Method signature
public Table<Row> GetTable(
  string tableName, GetTableOptions options = null
);
public Table<TRow> GetTable<TRow>(
  string tableName, GetTableOptions options = null
) where TRow : class;
public Table<TRow> GetTable<TRow>(
  GetTableOptions options = null
) where TRow : class, new();
Name Type Summary

tableName

string

The name of the table.

options

GetTableOptions

Optional. Options for this operation. Keyspace is required unless you specified a working keyspace when instantiating the Database object. For more information and examples for general options such as timeout and keyspace, see Customize API interaction.

Examples

The following examples demonstrate how to get a table.

Get a table

using DataStax.AstraDB.DataApi;
using DataStax.AstraDB.DataApi.Core;

namespace Examples;

public class Program
{
  static void Main()
  {
    // Get an existing table
    var client = new DataAPIClient(
      new CommandOptions() { Destination = DataAPIDestination.HCD }
    );

    var database = client.GetDatabase(
      "API_ENDPOINT",
      DataAPIClient.UsernamePasswordTokenProvider(
        "USERNAME",
        "PASSWORD"
      ),
      "KEYSPACE_NAME"
    );

    var table = database.GetTable("TABLE_NAME");
  }
}

Get a table and specify typing

using DataStax.AstraDB.DataApi;
using DataStax.AstraDB.DataApi.Core;
using DataStax.AstraDB.DataApi.Tables;

namespace Examples;

// Define the type for the table
[TableName("TABLE_NAME")]
public class Book
{
  [ColumnPrimaryKey(1)]
  [ColumnName("title")]
  public string Title { get; set; } = null!;

  [ColumnPrimaryKeySort(1, SortDirection.Ascending)]
  [ColumnName("number_of_pages")]
  public int NumberOfPages { get; set; }

  [ColumnPrimaryKey(2)]
  [ColumnName("rating")]
  public float Rating { get; set; }

  [ColumnName("genres")]
  public string[]? Genres { get; set; }

  [ColumnName("metadata")]
  public Dictionary<string, string>? Metadata { get; set; }

  [ColumnPrimaryKeySort(2, SortDirection.Descending)]
  [ColumnName("is_checked_out")]
  public bool IsCheckedOut { get; set; }

  [ColumnName("due_date")]
  public DateOnly? DueDate { get; set; }
}

public class Program
{
  static void Main()
  {
    // Get an existing table
    var client = new DataAPIClient(
      new CommandOptions() { Destination = DataAPIDestination.HCD }
    );

    var database = client.GetDatabase(
      "API_ENDPOINT",
      DataAPIClient.UsernamePasswordTokenProvider(
        "USERNAME",
        "PASSWORD"
      ),
      "KEYSPACE_NAME"
    );

    var table = database.GetTable<Book>();
  }
}

Client reference

For more information, see the client reference.

Was this helpful?

Give Feedback

How can we improve the documentation?

© Copyright IBM Corporation 2026 | Privacy policy | Terms of use Manage Privacy Choices

Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Pulsar, Pulsar, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries. Kubernetes is the registered trademark of the Linux Foundation.

General Inquiries: Contact IBM