Code
1 /// <summary>
2 // insert data
3 /// </Summary>
4 Public void insert (users _ users, idbtransaction transaction)
5 {
6 // create the inserted SQL statement
7 stringbuilder strsql = new stringbuilder ();
8 strsql. append ("insert into t_users ");
9 strSql. Append ("(UserId, UserName )");
10 strSql. Append ("values ");
11 strSql. Append ("(@ UserId, @ UserName )");
12
13 14 // create an array of inserted Parameters
15 OracleParameter [] parameters = {
16
17 // primary Id field
18 new OracleParameter ("@ UserId", OracleDbType. Varchar2, 20 ),
19 // User Name
20 new OracleParameter ("@ UserName", OracleDbType. Varchar2, 20)
21 };
22 _ users. UserId = BasicManage. GetSequences ("T_USERS", 6, "YYXXXXXX"); // This is just a method to return the sequence.
23 parameters [0]. Value = _ users. UserId;
24 parameters [1]. Value = _ users. UserName;
25
26 // execute the SQL statement
27 // OracleConnection conn = BasicManage. GetConn ();
28 try
29 {
30 BasicManage bm = new BasicManage ();
31 bm. ExecuteSQL (transaction, strSql. ToString (), parameters );
32 33
34}
35 catch (Exception ex)
36 {
37 transaction. Rollback ();
38 transaction. Connection. Close ();
39 throw ex;
40}
41} Let's look at this piece of code. In the SQL statement, @ UserId is on @ UserName. In Sqlserver, the order of Parameters below is unaffected, that is, if the parameters are correct, the order can be random. However, when connecting to oracle, the two parameters are definitely not in the wrong position. If the order is wrong, the operation will not report an error, but the data cannot be updated. I don't know if it is because of my problems, I adjusted the order correctly. The record is updated successfully. TIPS. I hope you don't have to worry about troubleshooting this problem.