/// <summary>
/// 统计接口调用次数
/// </summary>
public void UpdateInterfaceClickCount()
{
DataRow[] arrRows = updateTable.Select(string.Format("name='{0}'", InterfaceName));
if (arrRows.Length > 0)
{
DataRow row = arrRows[0];
row.BeginEdit();
row["click_count"] = (int)row["click_count"] + 1;
row.EndEdit();
}
else
{
DataRow dr = updateTable.NewRow();
dr["name"] = InterfaceName;
dr["click_count"] = 1;
dr["version"] = appversion;
updateTable.Rows.Add(dr);
}
if (updateTable.Rows.Count < 2) return;
new InterfaceCallDal().BatchUpdate(updateTable, updateTable.Rows.Count);
updateTable.Clear();
}
/// <summary>
/// 批量更新
/// </summary>
/// <param name="dataTable"></param>
/// <param name="batchSize">获取或设置一个值,该值启用或禁用批处理支持,并指定可以批处理执行的命令的数目。</param>
public void BatchUpdate(DataTable dataTable, Int32 batchSize)
{
try
{
dataTable.AcceptChanges();
foreach (DataRow row in dataTable.Rows)
{
row.SetModified();
}
// Assumes GetConnectionString() returns a valid connection string.
string connectionString = ConfigHelper.SQLConnection;
// Connect to the AdventureWorks database.
using (var connection = new SqlConnection(connectionString))
{
// Create a SqlDataAdapter.
var adapter = new SqlDataAdapter
{
UpdateCommand = new SqlCommand("update test_table SET click_count=click_count+@click_count WHERE name=@name and version=@version and app_type='app' ", connection)
};
// Set the UPDATE command and parameters.
adapter.UpdateCommand.Parameters.Add("@click_count", SqlDbType.Int, 4, "click_count");
adapter.UpdateCommand.Parameters.Add("@name", SqlDbType.VarChar, 128, "name");
adapter.UpdateCommand.Parameters.Add("@version", SqlDbType.VarChar, 10, "version");
//adapter.UpdateCommand.UpdatedRowSource = UpdateRowSource.None;
// Set the batch size.
//adapter.UpdateBatchSize = 0;
// Execute the update.
adapter.Update(dataTable);
}
}
catch
{
//ingore
}
}