Wednesday 7 July, 2010

CREATING A DATASET FROM SCRATCH

  1. using System;
  2. using System.Data;
  3. namespace CrtDataSet
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. //-- Instantiate the data set and table
  10. DataSet SongDS = new DataSet();
  11. DataTable songTable = SongDS.Tables.Add();
  12. //-- Add columns to the data table
  13. songTable.Columns.Add("ID", typeof(int));
  14. songTable.Columns.Add("Band", typeof(string));
  15. songTable.Columns.Add("Song", typeof(string));
  16. //-- Add rows to the data table
  17. songTable.Rows.Add(1, "Breaking Benjamin", "Diary of Jane");
  18. songTable.Rows.Add(2, "Three Days Grace", "Pain");
  19. songTable.Rows.Add(3, "Seether", "Fake It");
  20. songTable.Rows.Add(4, "Finger Eleven", "Paralyzer");
  21. songTable.Rows.Add(5, "Three Doors Down", "Citizen Soldier");
  22. //-- Cycle thru the data table printing the values to the screen
  23. foreach (DataTable table in SongDS.Tables)
  24. {
  25. foreach (DataRow row in table.Rows)
  26. {
  27. Console.WriteLine(row["Band"] + " ~ " + row["Song"]);
  28. }
  29. }
  30. }
  31. }
  32. }

No comments:

Post a Comment