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
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
List
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: