//需要在项目中引用System.Transactions
public static int vote(string id)
{
try
{
int result = 0;
using (TransactionScope tran = new TransactionScope()) //使用事务
{
string[] str = id.Split(',');
for (int i = 0; i < str.Length; i++)
{
if (str[i] != "")
{
string ip = System.Web.HttpContext.Current.Request.UserHostAddress;
result += new Common.DBIO().InsertVoteResults(Convert.ToInt32(str[i]), ip, DateTime.Now);
}
}
if (result == 10)
{
tran.Complete(); //提交事务
}
}
return result;
}
catch (Exception e)
{
return 0;
}
}