Home > Net >  SqlCommand. The Parameters. The Clear (); Cleared to return the primary key
SqlCommand. The Parameters. The Clear (); Cleared to return the primary key

Time:09-25

Transaction again, please perform SqlCommand. The Parameters. The Clear (), how can you will return to, the primary key as they are now returned after the implementation of the primary key is a 0,
This is executing SQL, list1 and list2 quantity is the same, the list1 [0] is returned to the primary key of SQL statements, performed after the clear () method is directly @ @ IDENTITY also cleared? , or the access to the primary key cannot be used in the transaction, great spirit under the guidance of bai thanks
Public static bool ExecSqlReturn (List List1 List{
SqlConnection con=SqlConn ();
SqlTransaction trans=null;
Try
{
SqlCommand Cmd=con. CreateCommand ();
Trans=con. BeginTransaction ();
Cmd. Connection=con;
Cmd. Transaction=trans;
for (int i=0; i {
Cmd.Com mandText=list1 [I];
Cmd. The Parameters. AddRange (list2 [I]);
Cmd. ExecuteNonQuery ();
Cmd. The Parameters. The Clear ();
}
Trans.Com MIT ();
return true;
}
}

This is the parameter
Public bool AddDict (T_D customer data td customer data, List{
List List1=new List (a);
ListString SQL="insert into D customer information (code, customer category, customer name, pinyin code, contact person, telephone, zip code, phone, fax, E-mail, the form, the address, shipping address, bank, account number, ID number, business scope, s special drug management s, business scope, special medicine, note) values (@ coding, @ customer category, @ customer full name, @ pinyin code, @ contacts, @ phone @ postcode, @, @ fax, @ email, @ form, @ address, @ shipping address, @ bank, @ account @ ein, @ s, @ special drug management s, @ business scope, @ special management of the drug, @ note) Select @ ID=@ @ IDENTITY".//SCOPE_IDENTITY ()
SqlParameter [] ps=new SqlParameter []
{
New SqlParameter (" @ ID ", SqlDbType. Int),
New SqlParameter (" @ coding, "td customer data. Code),
New SqlParameter (" @ customer category ", td customer data. Customer category),
New SqlParameter (" @ customer full name ", td customer data. The customer full name),
New SqlParameter (" @ "pinyin code, td customer data. Pinyin code),
New SqlParameter (" @ contacts, "td customer data. Contact),
New SqlParameter (" @ "phone, td customer data. The phone),
New SqlParameter (" @ zip code ", td customer data. Including zip code),
New SqlParameter (" @ mobile phone ", td customer data. Mobile phones),
New SqlParameter (" @ "fax, td customer data. Fax),
New SqlParameter (" @ email, "td customer data. Email),
New SqlParameter (" @ cargo terminal, "td customer data. Freight station),
New SqlParameter (" @ address, "td customer data. Address),
New SqlParameter (" @ shipping address ", td customer data. Delivery address),
New SqlParameter (" @ bank ", td customer data. Bank),
New SqlParameter (" @ account ", td customer information. Accounts),
New SqlParameter (" @ ein ", td customer data. Id number),
New SqlParameter (" @ business scope s ", td customer data. The business scope s),
New SqlParameter (" @ special drug management s, "td customer data. Special drug management s),
New SqlParameter (" @ scope of business, "td customer data. The business scope),
New SqlParameter (" @ special drug management ", td customer data. Special drug franchise),
New SqlParameter (" note "@, td customer data. Note)
};
Ps [0]. Direction=ParameterDirection. The Output;
Int the client code I=the Convert. ToInt32 (ps [0]. Value);
List1. Add (SQL);
List2. Add (ps);
for (int i=0; i {
String sql1="insert into d enterprise qualification (client code, logo, enterprise qualifications, certificate number, valid until, note) values (@ client code, the @ symbol, @ enterprise qualification, @ certificate number, @ will expire, @ note)";
/* string sql1="insert into d enterprise qualification (client code, logo, enterprise qualifications, certificate number, valid until, note) values (' {0} ', '{1}' and '{2}', '{3}', '{4}', '{5})";
Sql1=the string. Format (); */
List1. Add (sql1);
SqlParameter ps1=new SqlParameter [] []
{
New SqlParameter (" @ coding I "customer, the customer code I),//
New SqlParameter (" @ sign ", a list of qualifications [I]),
New SqlParameter (" @ enterprise qualification ", a list of qualifications [I] enterprise qualification),
New SqlParameter (" @ certificate number ", a list of qualifications [I] the certificate number),
New SqlParameter (" @ the validity to ", a list of qualifications [I] will be valid until),
New SqlParameter (" @ remark ", a list of qualifications [I] note),
};
List2. Add (ps1);
}
Return SQLHELPER. ExecSqlReturn (list1, list2);
}

CodePudding user response:

Don't have to out parameters,

For example:
Var SQL="insert into enterprise qualification (... ) values (... ); Select @ @ IDENTITY AS 'IDENTITY; ";
Var id=CMD. ExecuteScalar ();
The id is the id insert records (@ @ IDENTITY),

CodePudding user response:

reference 1st floor github_36000833 response:
don't have to out parameters,

For example:
Var SQL="insert into enterprise qualification (... ) values (... ); Select @ @ IDENTITY AS 'IDENTITY; ";
Var id=CMD. ExecuteScalar ();
The id is the id insert records (@ @ IDENTITY),

This I know, but this is a time I insert statements, the first statement of the system serial number is following statements customer code, I then write now, return to the primary key is 0, I don't know what reason

CodePudding user response:

You return in the Parameters, the output value of clear, of course, and the transaction is not the issue

CodePudding user response:

The
big watermelon a WuYiJin reference 3 floor? Response:
you return in the Parameters, the output value of removed is not, of course, is not a transaction problem

That how can receive the, no research to understand

CodePudding user response:

quoted Mr Night, 4/f, regression of response:
Quote: big watermelon a WuYiJin reference 3 floor? Response:
you return in the Parameters, the output value of removed is not, of course, is not a transaction problem

That how can receive the, no research understand

You take your statement ID defined as the output do
Declare @ ID int the output
  • Related