public void UpdateContactTableByDataSet(DataSet ds,string strTblName)
{
try
{
SqlDataAdapter myAdapter = new SqlDataAdapter();
SqlConnection conn = new SqlConnection(strConnection);
SqlCommand myCommand = new SqlCommand("select * from strTblName",conn);
myAdapter.SelectCommand = myCommand;
SqlCommandBuilder myCommandBuilder = new SqlCommandBuilder(myAdapter);
conn.Open();
SqlTransaction myTrans = conn.BeginTransaction();
myCommand.Transaction = myTrans;
try
{
myAdapter.Update(ds,strTblName);
myTrans.Commit();
}
catch(Exception e)
{
try
{
myTrans.Rollback();
}
catch (SqlException ex)
{
if (myTrans.Connection != null)
{
Console.WriteLine("回滾失敗! 異常類型: " + ex.GetType());
}
}
}
finally
{
conn.Close();
}
}
catch(Exception ex)
{
throw ex;
}
}