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 SGPRNY01 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();这个就是来读取里面字段的信息,其实note就是表在的字段
OracleCommand updateCmd = new OracleCommand("update SGPRNY01 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 //插入操作 25 OracleCommand cmd = new OracleCommand("insert into SGPRNY01(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 SGPRNY01(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是webconfig中配置的链接字符串;
读取的方法这常用的就是dateset和OracleDataReader,后者在上面的代码中举过例子了,dateset参见