Advertisement
Guest User

Untitled

a guest
Apr 24th, 2014
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. namespace WindowsFormsApplication1
  2. {
  3. public partial class Form1 : Form
  4. {
  5. private System.Data.DataSet dataSet;
  6. System.Data.DataTable table = new DataTable("ParentTable");
  7.  
  8. public Form1()
  9. {
  10. InitializeComponent();
  11. }
  12.  
  13. private void MakeParentTable()
  14. {
  15. DataColumn column;
  16. DataRow row;
  17.  
  18. column = new DataColumn();
  19. column.DataType = System.Type.GetType("System.Int32");
  20. column.ColumnName = "id";
  21. column.ReadOnly = true;
  22. column.Unique = true;
  23.  
  24. table.Columns.Add(column);
  25.  
  26. column = new DataColumn();
  27. column.DataType = System.Type.GetType("System.String");
  28. column.ColumnName = "ParentItem";
  29. column.AutoIncrement = false;
  30. column.Caption = "ParentItem";
  31. column.ReadOnly = false;
  32. column.Unique = false;
  33.  
  34. table.Columns.Add(column);
  35.  
  36. DataColumn[] PrimaryKeyColumns = new DataColumn[1];
  37. PrimaryKeyColumns[0] = table.Columns["id"];
  38. table.PrimaryKey = PrimaryKeyColumns;
  39.  
  40. dataSet = new DataSet();
  41.  
  42. dataSet.Tables.Add(table);
  43.  
  44. for (int i = 0; i<= 2; i++)
  45. {
  46. row = table.NewRow();
  47. row["id"] = i;
  48. row["ParentItem"] = "ParentItem " + i;
  49. table.Rows.Add(row);
  50. }
  51. }
  52.  
  53. private void Form1_Load(object sender, EventArgs e)
  54. {
  55. MakeParentTable();
  56. }
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement