Insert, update, and read oracle Data

Source: Internet
Author: User
1 private void insertIntoMes (string dayTime, string strNYCode, string strNYName, string strActWT, string strComName, string strNote)
2 {
3 string connectionString = ConfigurationManager. ConnectionStrings ["AppDBServer"]. ConnectionString;
4 OracleConnection con = new OracleConnection (connectionString );
5 con. Open ();
6 OracleCommand selectCmd = new OracleCommand ("select * from suplny01 where DATE_CODE =: v_date_CODE and NY_CODE =: v_ny_code", con );
7 selectCmd. Parameters. Add ("v_date_CODE", dayTime );
8 selectCmd. Parameters. Add ("v_ny_code", strNYCode );
9 OracleDataReader dr = selectCmd. ExecuteReader ();
10 if (dr. Read ())
11 {
12 // string str = dr ["NOTE"]. ToString (); this is used to read the information of fields in the table. In fact, note is the field in the table.
OracleCommand updateCmd = new OracleCommand ("update suplny01 set NY_NAME =: v_ny_name, ACT_WT =: v_act_wt, COM_NAME =: v_com_name, NOTE =: v_note, LOAD_TM =: v_load_tm where DATE_CODE =: v_date_CODE and NY_CODE =: v_ny_code ", con );
13 updateCmd. Parameters. Add ("v_date_CODE", dayTime );
14 updateCmd. Parameters. Add ("v_ny_code", strNYCode );
15 updateCmd. Parameters. Add ("v_ny_name", strNYName );
16 updateCmd. Parameters. Add ("v_act_wt", strActWT );
17 updateCmd. Parameters. Add ("v_com_name", strComName );
18 updateCmd. Parameters. Add ("v_note", strNote );
19 updateCmd. Parameters. Add ("v_load_tm", System. DateTime. Now );
20 updateCmd. ExecuteNonQuery ();
21}
22 else
23 {
24 // insert operation
25 OracleCommand cmd = new OracleCommand ("insert into suplny01 (DATE_CODE, NY_CODE, NY_NAME, ACT_WT, COM_NAME, NOTE, LOAD_TM) values (: v_date_CODE,: v_ny_code,: v_ny_name,: v_act_wt,: v_com_name,: v_note,: v_load_tm) ", con );
26 // OracleCommand cmd = new OracleCommand ("insert into suplny01 (DATE_CODE, LOAD_TM) values (: v_date_CODE,: v_load_tm)", con );
27 cmd. Parameters. Add ("v_date_CODE", dayTime );
28 cmd. Parameters. Add ("v_ny_code", strNYCode );
29 cmd. Parameters. Add ("v_ny_name", strNYName );
30 cmd. Parameters. Add ("v_act_wt", strActWT );
31 cmd. Parameters. Add ("v_com_name", strComName );
32 cmd. Parameters. Add ("v_note", strNote );
33 cmd. Parameters. Add ("v_load_tm", System. DateTime. Now );
34 cmd. ExecuteNonQuery ();
35}
36 con. Close ();
37}
AppDBServer is the link string configured in webconfig;
 
<connectionStrings>
<add name="AppDBServer" connectionString="user id=dagang; data source=orcl; password=dagang" providerName="System.Data.OracleClient"/>
</connectionStrings>

The method to read this commonly used is dateset and OracleDataReader, the latter in the code above for an example, dateset see http://www.cnblogs.com/vieri122/archive/2009/05/04/1449108.html


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.