C # connect to the Oracle database to query the changed data

Source: Internet
Author: User

The C # function introduced below after connecting to the Oracle database is to change the records in the database and query the changed data. If you are interested in connecting to the Oracle database, take a look.

 
 
  1. Using System;
  2. Using System. Collections. Generic;
  3. Using System. ComponentModel; // you must add system. data. oracleclient
  4. Using System. Data. OracleClient;
  5. Using System. Data;
  6. Using System. Drawing;
  7. Using System. Text;
  8. Using System. Windows. Forms;
  9.  
  10. Namespace WindowsApplication1
  11. {
  12. Public partial class Form1: Form
  13. {
  14. Public Form1 ()
  15. {
  16. InitializeComponent ();
  17. }
  18.  
  19. Private void button#click (object sender, EventArgs e)
  20. {
  21. # Region is manually written from region to endregion. Others are automatically generated by the system.
  22. String constring = "data source = wzd; user = wzd; password = wzd;"; // define the string to connect to the database
  23. OracleConnection conn = new OracleConnection (constring); // connect
  24. Try
  25. {
  26. Conn. Open (); // Open the specified connection
  27. OracleCommand com = conn. CreateCommand ();
  28. Com. CommandText = "select name from fin_ipr_inmaininfo where card_no = '000000'"; // write the SQL statement that you want to execute
  29. OracleDataReader odr = com. ExecuteReader ();
  30. While (odr. Read () // Read data. If the returned value is false, it indicates the end of the record set.
  31. {
  32. This. lbl. Text = odr. GetOracleString (0). ToString (); // display the read value to the defined control.
  33. }
  34. Odr. Close (); // Close reader. This must be written.
  35. }
  36. Catch
  37. {
  38. MessageBox. Show ("erro"); // if an exception occurs, an error is prompted.
  39. }
  40. Finally
  41. {
  42. Conn. Close (); // Close the opened connection
  43. }
  44.  
  45. # Endregion
  46. }
  47.  
  48. Private void button2_Click (object sender, EventArgs e)
  49. {
  50. # Region is manually written from region to endregion. Others are automatically generated by the system.
  51. String constring = "data source = wzd; user = wzd; password = wzd;"; // define the string to connect to the database
  52. OracleConnection conn = new OracleConnection (constring); // connect
  53. Try
  54. {
  55. Conn. Open (); // Open the specified connection
  56. OracleCommand com = conn. CreateCommand ();
  57. Com. CommandText = "update fin_ipr_inmaininfo set name = 'wzd' where card_no = '000000'"; // write the SQL statement that you want to execute
  58. Com. ExecuteNonQuery ();
  59.  
  60. }
  61. Catch
  62. {
  63. MessageBox. Show ("erro"); // if an exception occurs, an error is prompted.
  64. }
  65. Finally
  66. {
  67. Conn. Close (); // Close the opened connection
  68. }
  69.  
  70. # Endregion
  71. }
  72. }
  73. }


 
 

C # connect to the Oracle database to query data

Oracle RMAN backup Optimization

Oracle backup using RMAN

Learn about Oracle OS backup

Provides you with an in-depth understanding of how ORACLE runs.

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.