通过数据检索和插入来维护事务 [英] Maintain transaction with dataretrieve and inserting
本文介绍了通过数据检索和插入来维护事务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我在尝试翻译时遇到问题,遇到错误,请尝试帮助我
异常即将到来
System.InvalidOperationException:当分配给命令的连接处于暂挂的本地事务中时,ExecuteNonQuery要求该命令具有事务.该命令的Transaction属性尚未初始化.
告诉我如何才能做到最好
Hi
I have a problem when I''m trying transation I am getting error please try to help me
Exception is coming Exception is
System.InvalidOperationException: ExecuteNonQuery requires the command to have a transaction when the connection assigned to the command is in a pending local transaction. The Transaction property of the command has not been initialized.
tell me how I can do in best way
SqlCommand _sqlICommmand = new SqlCommand();
SqlConnection _sqlIConnection = new SqlConnection(_connectionString);
_sqlICommmand.Connection = _sqlIConnection;
if (_sqlIConnection.State == ConnectionState.Closed)
_sqlIConnection.Open();
_sqlICommmand.Transaction = transaction;
transaction = _sqlIConnection.BeginTransaction();
if (hiddenForRecoPlanType != "")
{
if (Convert.ToDecimal(hiddenForRecoPlanType) != a)
{
try
{
dstAssociatedUsersForFeed =GetAllSubscribedUsersToFeed(feedId);
dstCompany = GetCompanyNames(txtAddReco.Trim());
//_sqlICommmand.Transaction = transaction;
_sqlICommmand.CommandType = CommandType.StoredProcedure;
_sqlICommmand.CommandText = "SP_InsertIndividualPredictionsDetails";
_sqlICommmand.Parameters.Add(new SqlParameter("@feedId", feedId));
_sqlICommmand.Parameters.Add(new SqlParameter("@predictionMessage", dstCompany.Tables[0].Rows[0][1].ToString()));
_sqlICommmand.Parameters.Add(new SqlParameter("@market", Convert.ToString(market)));
_sqlICommmand.Parameters.Add(new SqlParameter("@recommendationPrice", hiddenForRecoPlanType));
_sqlICommmand.Parameters.Add(new SqlParameter("@expectedPrice", targateprice));
_sqlICommmand.Parameters.Add(new SqlParameter("@predictionPostDate", DateTime.Now.ToString()));
if (_sqlIConnection.State == ConnectionState.Closed)
_sqlIConnection.Open();
_sqlICommmand.ExecuteNonQuery();
DataSet dstGetAllFeedStatusWhileRecoPosting = new DataSet();
DataSet _dstsellerPayment = new DataSet();
dstGetAllFeedStatusWhileRecoPosting = GetAllFeedStatusWhileRecoPosting(feedId);
if (_sqlICommmand.Parameters.Contains("@feedId"))
{
_sqlICommmand.Parameters.RemoveAt("@feedId");
}
if (_sqlICommmand.Parameters.Contains("@predictionMessage"))
{
_sqlICommmand.Parameters.RemoveAt("@predictionMessage");
}
if (_sqlICommmand.Parameters.Contains("@market"))
{
_sqlICommmand.Parameters.RemoveAt("@market");
}
if (_sqlICommmand.Parameters.Contains("@recommendationPrice"))
{
_sqlICommmand.Parameters.RemoveAt("@recommendationPrice");
}
if (_sqlICommmand.Parameters.Contains("@expectedPrice"))
{
_sqlICommmand.Parameters.RemoveAt("@expectedPrice");
}
if (_sqlICommmand.Parameters.Contains("@predictionPostDate"))
{
_sqlICommmand.Parameters.RemoveAt("@predictionPostDate");
}
int rowcount = dstGetAllFeedStatusWhileRecoPosting.Tables[0].Rows.Count;
if (dstGetAllFeedStatusWhileRecoPosting != null && rowcount > 0)
{
for (int datacount = 0; datacount < rowcount; datacount++)
{
_sqlICommmand.CommandType = CommandType.StoredProcedure;
_sqlICommmand.CommandText = "SP_InsertFeedIncome";
_sqlICommmand.Parameters.Add(new SqlParameter("@feedId", feedId));
_sqlICommmand.Parameters.Add(new SqlParameter("@scheme", dstGetAllFeedStatusWhileRecoPosting.Tables[0].Rows[datacount][2].ToString()));
_sqlICommmand.Parameters.Add(new SqlParameter("@userID", Convert.ToInt32(dstGetAllFeedStatusWhileRecoPosting.Tables[0].Rows[datacount][0])));
_sqlICommmand.Parameters.Add(new SqlParameter("@recosGot", 1));
_sqlICommmand.Parameters.Add(new SqlParameter("@recosTotal", Convert.ToInt32(dstGetAllFeedStatusWhileRecoPosting.Tables[0].Rows[datacount][1])));
if (_sqlIConnection.State == ConnectionState.Closed)
_sqlIConnection.Open();
_sqlICommmand.ExecuteNonQuery();
//_dstsellerPayment = InsertFeedIncome( dstGetAllFeedStatusWhileRecoPosting.Tables[0].Rows[datacount][2].ToString(), Convert.ToInt32(dstGetAllFeedStatusWhileRecoPosting.Tables[0].Rows[datacount][0]), 1, Convert.ToInt32(dstGetAllFeedStatusWhileRecoPosting.Tables[0].Rows[datacount][1]));
}
}
DataSet dstGetSubscriptionStatusChange = new DataSet();
dstGetSubscriptionStatusChange = GetSubscriptionStatusChange(feedId);
transaction.Commit();
result="susscess";
}
catch (SqlException se)
{
transaction.Rollback();
}
catch (Exception ex)
{
transaction.Rollback();
}
推荐答案
当您遇到从未遇到过的错误时,应该做的第一件事就是将错误消息发送给Google.
我代表您做到了,我获得的第一印象是 ^ ].
现在它可能无法解决您的问题,但如果没有答案,我愿意打赌其他热门游戏之一也可以.
继续尝试一下. :)
When you get an error that you have never encountered before, one of the first things you should do is to Google the error message.
I did it on your behalf and the first hit I got was to this[^] on MSDN.Social.
Now it may not have the answer to your problem but if it doesn''t I''d be willing to bet that one of the other hits will.
Go on, give it a try. :)
这篇关于通过数据检索和插入来维护事务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文