My requirement is For a DataSet, Create multiple Datables dynamically and add them to Dataset dynamically in C#. I need to store more than 30 million dataset in memory that consist of a sql table of columns and 30 million+ rows.
I will get the data from DB to datareader if the and I add that data to new row and add to datatable if the rowCount==5000 I have to create a new datatable dynamically and add that datatable to the dataset dynamically.
In case if you dont find my approach is healthy please suggest a new one.
SqlDataReader reader = objCmd.ExecuteReader();
tmp = new DataSet();
while (reader.Read())
{
if(counter == 0)
{
string tableName = "Table_" + tableCount;
output = new DataTable(tableName);
tmp.Tables.Add(output);
output = tmp.Tables[tableCount];
output.Columns.Add("col1", typeof(string));
output.Columns.Add("col2", typeof(string));
output.Columns.Add("col3", typeof(string));
output.Columns.Add("col4", typeof(string));
output.Columns.Add("col5", typeof(string));
output.Clear();
output.Dispose();
}
output.Rows.Add(reader.GetValue(0), reader.GetValue(1), reader.GetValue(2), reader.GetValue(3), reader.GetValue(4));
counter++;
while (counter == 5000)
{
tableCount++;
counter = 0;
}
}
My problem is it is not adding rows. It is adding empty table.