DatSet to DataTableReader in C#

I have fetched data from database as a complete dataset which has only one table in it.

Made a DataTableReader from it and it is working as same as DataReader.

Simple Example Below.

DataBase.cs

public static class DataBase

{

private static VerticaConnection vConnection = null;

private static VerticaCommand vCommand = null;

private static VerticaDataAdapter vAdapter = null;

string private static void GetConnection()

{

GetAppSettings(); //get connection string from config

vConnection = new VerticaConnection(<connectionstring>);

vCommand = new VerticaCommand();

vAdapter = new VerticaDataAdapter(vCommand);

}

public static System.Data.DataSet getData(string query)

{

try{

GetConnection();

vCommand.CommandText = query;

vCommand.Connection = vConnection;

vAdapter.SelectCommand = vCommand;

System.Data.DataSet ds = new System.Data.DataSet();

vAdapter.Fill(ds);

return ds;

}catch(Exception ex)

{

throw ex;

}

}

}

Programs.cs
 

class Program

{

    static void Main(string[] args)

    {

        string query = "<Select Query>";

        System.Data.DataSet ds = DataBase.getData(query);

        System.Data.DataTableReader dr = ds.CreateDataReader();

        Console.Write(dr.FieldCount);

        while (dr.Read())

        {

            if (dr.HasRows)

            {

                for (int i = 0; i < dr.FieldCount; i++)

                {

                    Console.Write(dr[i].ToString() + "--");

                }

            }

            Console.WriteLine();

        }

        Console.Read();

    }

}

Ebook Download
View all
Learn
View all