C # directly create a able and add data to it (custom datatable)

Source: Internet
Author: User

Http://blog.csdn.net/diyoosjtu/article/details/7585111

 

[CSHARP]
View plaincopyprint?
  1. Datatable dt = new datatable ("cart ");
  2. Datacolumn DC1 = new datacolumn ("prizename", type. GetType ("system. String "));
  3. Datacolumn DC2 = new datacolumn ("point", type. GetType ("system. int16 "));
  4. Datacolumn DC3 = new datacolumn ("Number", type. GetType ("system. int16 "));
  5. Datacolumn dc4 = new datacolumn ("totalpoint", type. GetType ("system. int64 "));
  6. Datacolumn dC5 = new datacolumn ("prizeid", type. GetType ("system. String "));
  7. DT. Columns. Add (DC1 );
  8. DT. Columns. Add (DC2 );
  9. DT. Columns. Add (DC3 );
  10. DT. Columns. Add (dc4 );
  11. DT. Columns. Add (dC5 );
  12. // The above code completes the datatable architecture, but there is no data in it
  13. For (INT I = 0; I <10; I ++)
  14. {
  15. Datarow DR = DT. newrow ();
  16. Dr ["prizename"] = "doll ";
  17. Dr ["point"] = 10;
  18. Dr ["Number"] = 1;
  19. Dr ["totalpoint"] = 10;
  20. Dr ["prizeid"] = "001 ";
  21. DT. Rows. Add (DR );
  22. }
  23. // Fill in 10 identical records
  24. Someone will do this.
  25. Datarow DR = new datarow ();
  26. ..
  27. DT. Rows. Add (DR );
  28. This is not acceptable, because a datarow must belong to a datatable and cannot be created out of thin air, just as a record must belong to a table.
  29. Someone else does this.
  30. Datarow DR = DT. newrow ();
  31. Dr ["prizename"] = "doll ";
  32. Dr ["point"] = 10;
  33. Dr ["Number"] = 1;
  34. Dr ["totalpoint"] = 10;
  35. Dr ["prizeid"] = "001 ";
  36. For (INT I = 0; I <10; I ++)
  37. {
  38. DT. Rows. Add (DR );
  39. }
  40. This is also wrong, because the datatable already has this datarow, it is like a table that cannot have two identical records, each time newrow ()

 

[CSHARP]
View plaincopyprint?
  1. Datatable dt = new datatable ("cart ");
  2. Datacolumn DC1 = new datacolumn ("prizename", type. GetType ("system. String "));
  3. Datacolumn DC2 = new datacolumn ("point", type. GetType ("system. int16 "));
  4. Datacolumn DC3 = new datacolumn ("Number", type. GetType ("system. int16 "));
  5. Datacolumn dc4 = new datacolumn ("totalpoint", type. GetType ("system. int64 "));
  6. Datacolumn dC5 = new datacolumn ("prizeid", type. GetType ("system. String "));
  7. DT. Columns. Add (DC1 );
  8. DT. Columns. Add (DC2 );
  9. DT. Columns. Add (DC3 );
  10. DT. Columns. Add (dc4 );
  11. DT. Columns. Add (dC5 );
  12. // The above code completes the datatable architecture, but there is no data in it
  13. For (INT I = 0; I <10; I ++)
  14. {
  15. Datarow DR = DT. newrow ();
  16. Dr ["prizename"] = "doll ";
  17. Dr ["point"] = 10;
  18. Dr ["Number"] = 1;
  19. Dr ["totalpoint"] = 10;
  20. Dr ["prizeid"] = "001 ";
  21. DT. Rows. Add (DR );
  22. }
  23. // Fill in 10 identical records
  24. Someone will do this.
  25. Datarow DR = new datarow ();
  26. ..
  27. DT. Rows. Add (DR );
  28. This is not acceptable, because a datarow must belong to a datatable and cannot be created out of thin air, just as a record must belong to a table.
  29. Someone else does this.
  30. Datarow DR = DT. newrow ();
  31. Dr ["prizename"] = "doll ";
  32. Dr ["point"] = 10;
  33. Dr ["Number"] = 1;
  34. Dr ["totalpoint"] = 10;
  35. Dr ["prizeid"] = "001 ";
  36. For (INT I = 0; I <10; I ++)
  37. {
  38. DT. Rows. Add (DR );
  39. }
  40. This is also wrong, because the datatable already has this datarow, it is like a table that cannot have two identical records, each time newrow ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.