Using presqldata. dataprocess;

Source: Internet
Author: User

 

  1. UsingSystem;
  2. UsingSystem. Collections. Generic;
  3. UsingSystem. componentmodel;
  4. UsingSystem. Data;
  5. UsingSystem. drawing;
  6. UsingSystem. LINQ;
  7. UsingSystem. text;
  8. UsingSystem. Windows. forms;
  9. UsingSystem. Data. sqlclient;
  10. NamespaceAllsavegrid
  11. {
  12. PublicPartialClassForm1: Form
  13. {
  14. Dataset DS =NewDataset ();
  15. PublicForm1 ()
  16. {
  17. Initializecomponent ();
  18. Gridcontrol_bind ();
  19. }
  20. Public VoidGridcontrol_bind ()
  21. {
  22. Sqlclass SC =NewSqlclass ();
  23. // Dataset DS = new dataset ();
  24. DS = SC. seltable ();// Obtain the data source of the datagridview.
  25. Datagridview1.datasource = Ds. Tables [0];
  26. }
  27. Private VoidButton#click (ObjectSender, eventargs E)
  28. {
  29. Sqlconnection con =NewSqlconnection ("Server = 'localhost'; database = 'work'; user = 'sa '; Password = '000000 '");
  30. Sqlcommand cmd =NewSqlcommand ();
  31. Cmd = con. createcommand ();
  32. Cmd. commandtext ="Select * From table_gongzi";
  33. Sqldataadapter da =NewSqldataadapter (CMD );
  34. Sqlcommandbuilder cb =NewSqlcommandbuilder (DA );// If sqlcommandbuilder is used, your table must first have a primary key.
  35. // Then, the insert, modify, and delete statements are generated based on the query statements you provide.
  36. // Then, the corresponding statement is called Based on the Data row status of the datatable to perform database operations.
  37. Da. Update (Ds. Tables [0]);
  38. Datagridview1.update ();
  39. }
  40. Private VoidButton2_click (ObjectSender, eventargs E)
  41. {
  42. Datarowview DRV = maid [0]. databounditemAsDatarowview;
  43. DRV. Delete ();
  44. Sqlconnection con =NewSqlconnection ("Server = 'localhost'; database = 'work'; user = 'sa '; Password = '000000 '");
  45. Sqlcommand cmd =NewSqlcommand ("Select * From table_gongzi", Con );
  46. // Sqlcommand cmd = new sqlcommand ();
  47. // Cmd = con. createcommand ();
  48. // Cmd. commandtext = "select * From table_gongzi ";
  49. Sqldataadapter da =NewSqldataadapter (CMD );
  50. Sqlcommandbuilder cb =NewSqlcommandbuilder (DA );// New sqlcommandbuilder is required; otherwise, an error is returned for DA. Update.
  51. Da. Update (Ds. Tables [0]);
  52. Datagridview1.update ();
  53. }
  54. }
  55. }

 

Reprinted statement:This article from http://blog.csdn.net/shanzhaikaifa/archive/2009/08/13/4443931.aspx

 

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.