About the order of parameters for. net operations on Oracle databases.

Source: Internet
Author: User

 

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.

 

 

Related Article

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.