Count Order Quantity Different Connectors

Code


[TestMethodAttribute("DataTable")]
public void Method0()
{
SqlConnection connec = new SqlConnection(ConfigurationManager.ConnectionStrings["CountOrderQuantityDifferentConnectors.Properties.Settings.AdventureWorks2008R2ConnectionString"].ConnectionString);
DataTable dt = new DataTable();
connec.Open();
SqlCommand cmd = new SqlCommand("select * from Sales.SalesOrderDetail", connec);
SqlDataReader reader = cmd.ExecuteReader();
dt.Load(reader);
reader.Close();
reader.Dispose();
reader = null;
cmd.Dispose();
long totalOrderQty = 0;
foreach (DataRow dr in dt.Rows)
{
totalOrderQty += Convert.ToInt64(dr["OrderQty"]);
}
dt.Dispose();
dt = null;
connec.Close();
connec.Dispose();
connec = null;
}

[TestMethodAttribute("SqlDataReader")]
public void Method1()
{
SqlConnection connec = new SqlConnection(ConfigurationManager.ConnectionStrings["CountOrderQuantityDifferentConnectors.Properties.Settings.AdventureWorks2008R2ConnectionString"].ConnectionString);
connec.Open();
SqlCommand cmd = new SqlCommand("select * from Sales.SalesOrderDetail", connec);
SqlDataReader reader = cmd.ExecuteReader();
long totalOrderQty = 0;
if (reader != null)
{
while (reader.Read())
{
totalOrderQty += Convert.ToInt64(reader["OrderQty"]);
}
}
reader.Close();
reader.Dispose();
reader = null;
cmd.Dispose();
connec.Close();
connec.Dispose();
connec = null;
}

[TestMethodAttribute("adapter.GetData()")]
public void Method2()
{
dsDataTableAdapters.SalesOrderDetailTableAdapter adapter = new dsDataTableAdapters.SalesOrderDetailTableAdapter();
long totalOrderQty = 0;
foreach (dsData.SalesOrderDetailRow data in adapter.GetData())
{
totalOrderQty += Convert.ToInt64(data.OrderQty);
}
}

[TestMethodAttribute("adapter.Fill(dsData.SalesOrderDetailDataTable)")]
public void Method3()
{
dsDataTableAdapters.SalesOrderDetailTableAdapter adapter = new dsDataTableAdapters.SalesOrderDetailTableAdapter();
dsData.SalesOrderDetailDataTable dt = new dsData.SalesOrderDetailDataTable();
adapter.Fill(dt);
long totalOrderQty = 0;
foreach (dsData.SalesOrderDetailRow data in dt)
{
totalOrderQty += Convert.ToInt64(data.OrderQty);
}
dt.Dispose();
dt = null;
}

[TestMethodAttribute("DataTable Just OrderQty Column")]
public void Method4()
{
SqlConnection connec = new SqlConnection(ConfigurationManager.ConnectionStrings["CountOrderQuantityDifferentConnectors.Properties.Settings.AdventureWorks2008R2ConnectionString"].ConnectionString);
DataTable dt = new DataTable();
connec.Open();
SqlCommand cmd = new SqlCommand("select OrderQty from Sales.SalesOrderDetail", connec);
SqlDataReader reader = cmd.ExecuteReader();
dt.Load(reader);
reader.Close();
reader.Dispose();
reader = null;
cmd.Dispose();
long totalOrderQty = 0;
foreach (DataRow dr in dt.Rows)
{
totalOrderQty += Convert.ToInt64(dr["OrderQty"]);
}
dt.Dispose();
dt = null;
connec.Close();
connec.Dispose();
connec = null;
}

[TestMethodAttribute("SqlDataReader Just OrderQty Column")]
public void Method5()
{
SqlConnection connec = new SqlConnection(ConfigurationManager.ConnectionStrings["CountOrderQuantityDifferentConnectors.Properties.Settings.AdventureWorks2008R2ConnectionString"].ConnectionString);
connec.Open();
SqlCommand cmd = new SqlCommand("select OrderQty from Sales.SalesOrderDetail", connec);
SqlDataReader reader = cmd.ExecuteReader();
long totalOrderQty = 0;
if (reader != null)
{
while (reader.Read())
{
totalOrderQty += Convert.ToInt64(reader["OrderQty"]);
}
}
reader.Close();
reader.Dispose();
reader = null;
cmd.Dispose();
connec.Close();
connec.Dispose();
connec = null;
}

Results

image0

Downloads

Buffer