Monthly Archives: December 2012

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; […]

0  

Read Text File

Code const string filePath = “.\names.txt”; [TestMethodAttribute("File.ReadAllText")] public void Method0() { string allData = File.ReadAllText(filePath); } [TestMethodAttribute("StreamReader.ReadToEnd")] public void Method1() { StreamReader sr = new StreamReader(filePath); string allData = sr.ReadToEnd(); sr.Close(); sr.Dispose(); sr = null; } [TestMethodAttribute("BinaryReader.ReadString")] public void Method2() { StreamReader sr = new StreamReader(filePath); BinaryReader br = new BinaryReader(sr.BaseStream); string allData = br.ReadString(); […]

0