TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
ahmed elbarbary
NA
1.6k
278k
are transaction implemented success on this function or not
Jun 1 2020 7:48 PM
I work on csharp function I make enhance to function by add transaction but i dont know
transaction implemented success or it have some thing wrong :
I need answer acording to logic :
public
static
DataTable ExecuteDataTablesp(string sql, SqlConnection dbConnection, DbParameter[] @params =
null
, CommandType cmdType = CommandType.StoredProcedure)
{
SqlCommand cmd1 =
null
;
SqlDataAdapter DA1 =
null
;
if
(dbConnection ==
null
)
{
if
(WithTransaction)
dbConnection = (SqlConnection)BeginTransaction();
else
dbConnection = (SqlConnection)InitializeConnection();
}
switch
(Provider)
{
case
Providers.SQLServer:
cmd1 =
new
SqlCommand(
""
, dbConnection as SqlConnection);
DA1 =
new
SqlDataAdapter(
""
, dbConnection as SqlConnection);
if
(WithTransaction && _transaction.Connection !=
null
&& _transaction.Connection.State == ConnectionState.Open)
{
cmd1.Transaction = (SqlTransaction)_transaction;
cmd1.Connection = (SqlConnection)_transaction.Connection;
}
break
;
default
:
break
;
}
if
(sql ==
""
)
return
new
DataTable();
DataSet ds =
new
DataSet();
try
{
lock (synObj)
{
sql = AnalyizeBooleanFields(sql);
cmd1.CommandText = sql;
cmd1.CommandType = cmdType;
cmd1.Parameters.Clear();
if
(@params !=
null
&& @params.Length > 0)
{
cmd1.Parameters.AddRange(@params);
}
if
(WithTransaction && _transaction.Connection !=
null
&& _transaction.Connection.State == ConnectionState.Open)
{
cmd1.Transaction = (SqlTransaction)_transaction;
cmd1.Connection = (SqlConnection)_transaction.Connection;
}
else
{
if
(string.IsNullOrEmpty(dbConnection.ConnectionString))
dbConnection.ConnectionString = CreateConnectionString(CurrentDataBase);
if
(dbConnection.State != ConnectionState.Open)
dbConnection.Open();
}
// if (WithTransaction) cmd1.Transaction = _transaction;
cmd1.CommandTimeout = 0;
DA1.SelectCommand = cmd1;
DA1.Fill(ds);
if
(!WithTransaction && dbConnection.State == ConnectionState.Open)
dbConnection.Close();
}
if
(WithTransaction)
{
_transaction.Commit();
}
}
catch
{
_transaction.Rollback();
}
if
(WithTransaction && _transaction.Connection.State == ConnectionState.Open)
{
dbConnection.Close();
}
return
ds.Tables[0];
}
Reply
Answers (
3
)
I have publish video on C-sharp corner
Converting InAppBilling.Plugin to Amazon