Tomas
Tomas

Reputation: 18097

read data from ODBC using DataSet

I have created ODBS user DNS for database, opened VS, created DataSet and imported one table members. I would like to read all records from dataset, how to do that? I have tried query below but it return no result. I can preview data using preview menu in designer but do not find a way to get data using code.

    var dataSet = new DataSet1();        
    var membersDataTable = dataSet.members;

    var take = membersDataTable.Take(100);

Upvotes: 0

Views: 15305

Answers (1)

mgnoonan
mgnoonan

Reputation: 7200

It looks like you have created the schema for a DataSet, but you have not run any queries to load the DataSet.

using (OdbcConnection connection = 
               new OdbcConnection(connectionString))
    {
        string queryString = "SELECT * FROM Members";
        OdbcDataAdapter adapter = 
            new OdbcDataAdapter(queryString, connection);

        // Open the connection and fill the DataSet.
        try
        {
            connection.Open();
            adapter.Fill(dataSet);
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
        // The connection is automatically closed when the
        // code exits the using block.

Upvotes: 4

Related Questions