public void UpdateData(string strSN)
{
SqlTransaction objTrans = null;
SqlBulkCopy objBulkCopy = null;
DataTable objDt = new DataTable();
DataRow dr = null;
if (!objDt.Columns.Contains("id"))
{
objDt.Columns.Add("id");
}
if (!objDt.Columns.Contains("s"))
{
objDt.Columns.Add("s");
}
if (!objDt.Columns.Contains("formation_time"))
{
objDt.Columns.Add("formation_time");
}
try
{
string[] dtS = strSN.Split(';');
foreach (string S in dtS)
{
if (string.IsNullOrEmpty(S))
{
continue;
}
dr = objDt.NewRow();
dr["S"] = S.Trim();
dr["formation_time"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
objDt.Rows.Add(dr);
}
if (this.Connection.State != ConnectionState.Open)
{
this.Connection.Open();
}
objTrans = this.Connection.BeginTransaction();
objBulkCopy = new SqlBulkCopy(this.Connection, SqlBulkCopyOptions.TableLock, objTrans);
objBulkCopy.DestinationTableName = "s";
objBulkCopy.WriteToServer(objDt);
objTrans.Commit();
}
catch (Exception ex)
{
if (objTrans != null)
{
objTrans.Rollback();
}
throw ex;
}
finally
{
if (objBulkCopy != null)
{
objBulkCopy.Close();
}
if (this.Connection != null)
{
if (this.Connection.State != ConnectionState.Closed)
{
this.Connection.Close();
}
}
}