Month: February 2020

Using backgroundworkers with progress reporting and cancelation

With the release of VS11 around the corner and the new async features in there everyone will have a wide toolset for writing non blocking responsive applications. If you have not yet played with the beta versions or regular threads (see for example Threads and the threadpool then the backgroundworker is the most basic component to help you get started. Minimal example with parameter passing and error handling This examples shows how to: Run a […]

Coloring individual cells or rows in a DX Gridcontrol based on a cell value

Coloring individual cells This sample hooks into the RowCellStyle event of the Gridview, and evaluates the value of the cell. Depending on the outcome, a background color is assigned to the cell. private void gridViewQueue_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e) { var oView = (GridView)sender; if (e.Column.FieldName == “task_stamp”) { Color oBgcolor; var dtValue = DateTime.Parse(oView.GetRowCellValue(e.RowHandle, “task_stamp”).ToString()); if (dtValue < DateTime.Now) { oBgcolor = Color.LightGreen; } else { oBgcolor = Color.LightYellow; } if (dtValue.Hour == 20) { […]

Distinct, join and outer Join with linq to sql

While stored procedures will beat linq most of the time if you want top notch performance, there is a distinct advantage to LINQ when it comes to readability of your code, and keeping things a little more central within the application. These samples make use of the NorthWind database, and a dbml file called NorthWindContext.dbml which has been created with the sqlmetal utility that comes with Visual Studio. in these samples they are loaded with […]

Importing data from an Excel sheet

C# Example using System; using System.Collections.Generic; using System.Data; using System.Data.OleDb; using System.Linq; using System.Text; namespace Excel2Table { public class ExcelReader { /// <summary> /// Reads an excel file with OLEDB, and returns a datatable object from the content. The sheet to be imported /// needs to be named “Import” in the excel file. /// </summary> /// <param name=”sFilehandle”>Complete path to the excel file, including the filename and extension</param> /// <returns>A datatable containing the imported file</returns> […]

Threads and the Threadpool

This small demonstration code snippet will show you how to: Create threads to run code in the background of your application Demonstrate how to pass one or more parameters to a background thread Demonstrate how to wait for all background activity to finish before exiting the main program. using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; namespace ConsoleApplicationThreadTest { /// <summary> /// This is a simple demonstration of starting background tasks for processing and passing […]

Using LINQ with MySQL

This code demonstrates access to OSCOMMERCE database objects which are hosted on a mysql server, through the enitity framework and LINQ. Additionaly, the connectionstring is overriden at runtime to seperate developent and production environments. Install the MySql connector for visual studio Add a ADO.NET Entity data object to the solution Use the Wizard to create the object context (adding the tables product and products_descriptions for this example If you use VS2012: Remove the .tt files […]

Resursively listing a directory tree using a stack object

The class offered below shows an implementation of an efficient way to scan large filesystem trees and returning the content. By not using recursion but controlling the worklist with a stack element a large part of the load on the GC is reduced. Using recursion the collection of created objects by the recusrive calls can’t be unwind until the entire process is completed, while by using a stack this control is left with the programmer. […]

Enabling Powershell Hyper-V cmdlets on upgraded systems

One of the great things added with Server 2012 (and Windows 8) is full support for Hyper-V in powershell. There is a long list of cmdlets that make managing virtual machines a breeze. (see: this technet link ). If you upgraded a server from Server 2008/2008R2 to Server 2012 you will find the cmdlet’s oddly missing … The upgrade did install the new version of Hyper-V but did not add the powershell management library to […]

HYPER-V Back Script, with optional suspend or stop of the virtual machine

With the help of the powershell applets for HYPER-V it has become quite easy to create a reliable backup of your virtual machines without the need for highly expensive backup tools. The script uses the standard export functionality build into HYPER-V, so you can restore one of these backup’s to the actual virtual machine including the unique identifiers Adept the configuration section at the top of the script with the network locations of your choosing. […]

Failed to generate a user instance of SQL Server due to failure in retrieving the user’s local application data path

When publishing a web application which includes an integrated SQL database you receive the following error: Failed to generate a user instance of SQL Server due to failure in retrieving the user’s local application data path. Please make sure the user has a local user profile on the computer. The connection will be closed. Cause: The user identity your application is trying to create an instance of the SQL server with, does not have a […]

Next Page »