1
내 코드의 문제는 어디에 있습니까?저장 프로 시저에 매개 변수 보내기
저장 프로 시저 및 트랜잭션을 사용합니다.
하나의 매개 변수가 제대로 작동하지만 매개 변수 수가 둘 이상인 경우 오류가 발생합니다.
내 문제는 어디에 있습니까?
이 C#을
internal static bool ExecuteNonQueryTransaction(string CommandName, CommandType cmdType, SqlParameter[][] pars)
{
int result = 0;
SqlTransaction tr = null;
int h = pars.GetLength(0);
using (SqlConnection con = new SqlConnection(CONNECTION_STRING))
{
if (con.State != ConnectionState.Open)
{
con.Open();
}
try
{
tr = con.BeginTransaction();
using (SqlCommand cmd = con.CreateCommand())
{
cmd.CommandType = cmdType;
cmd.Transaction = tr;
cmd.CommandText = CommandName;
// cmd.Parameters.AddRange(pars);
for (int i = 0; i < pars.GetLength(0); i++)
{
cmd.Parameters.AddRange(pars[i]);
cmd.ExecuteNonQuery();
}
tr.Commit();
}
}
catch
{
if (tr != null)
{
tr.Rollback();
}
//return false;
}
}
return (result > 0);
}
내 코드와
ALTER PROCEDURE dbo.AddNewUserTypePageAccess
(@id_user_type int,
@id_page_access int)
as
insert into user_type_page_access(id_user_type, id_page_access)
values(@id_user_type, @id_page_access)
return
여러분의 도움에 감사드립니다이 내 저장 프로 시저 .....
나는했지만 그것은 작동하지 않았다. 나는 저장 프로 시저를 n 번 실행하고 모두가 가장 트랜잭션이되기를 원한다. 나는 2 개의 매개 변수를 n 번 전송합니다. – nimaSadeghpour