Tag Archives: C-Sharp

Quickly implement nLogging to a MS SQL Database

The following blog post will give you a short toturial on implementing nLog into a system logging logs to the database. Right click on a project/solution that you want to implement nLogging into, I just have a seperate assembly that I add to my projects. Search for nLog in the search bar in the top […]


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


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