Programming Examples

Are you a Programmer or Application Developer or a DBA? Take a cup of coffee, sit back and spend few minutes here :)

C#

Articles on C# programming language.

Creating Custom Performance Counter in C#

Objects involved in custom performance counter

The Register and Leave button share same Performance Counter called Register Click and Update button uses a one more Counter called Update Click. This example form increments the Counters Register Click and Update Click when user clicks the relevant buttons Register and Update. The Leave button will reduce the Register Click performance count by one. This example looks hollow. But it is just for a tryout purpose.

In the real case, these kinds of click counts are useful to measure Performance of the Operator. Say, for example, a click count on the print button measures how many billing is done in an hour by an operator on the billing counter of a retail shop. The perfmon can plot the graph over time, showing how many billing a billing counter staff clears. You can think of a better example than this one once you know how this Example works.

Continue Reading →

Spawning A Process in C#

C# Spawn Process Example

The sample application has two parts. The first part starts a notepad process when you click the ‘Start’ (Marked as 1) button. You can enter the text document location in the text box (Marked as 2) before clicking the start button. When a text document is specified, the notepad process opens that document.

In the second part, the example app runs the batch as a process when we click the start button (Marked as 7). The batch file performs a ‘DOS Copy’ operation, which requires Source and Destination locations. We can supply these data can through two text boxes (Marked as 3 & 4). When a batch file execution continues, we can see a console window in the background. The checkbox ‘Make Silent’ (marked as 5) suppresses the background command window. The checkbox ‘Notify when closed’ (Marked as 6) when checked, allows the application receiving the notification when process finished its operation. In our case, when the batch file completes the copy action, our example gets a notification.

Continue Reading →

Multiple Result Sets Processing in Ado.net

About ADO.Net Multiple ResultSet Processing Example

In this Example, we will see packing more than one SQL statement in a SqlCommand and process it through the SqlDataReader object. From the past articles on ado.net we are already familiar with Connection, Command and Reader objects. Hence, we will focus on dealing with multiple result sets.

The example retrieves the data from the SQL Server sample database Pubs. A total number of authors queried from the table authors is displayed in a label control marked as 1 and author name from the same table is displayed in the combo box item marked as 2. The list box marked as 3 displays all store names by querying the table stores from the Pubs database. When we click the Get Data button (Marked as 4), the example fetches all the data through a single SqlCommand formed by three SQL statements.

Continue Reading →

Dynamically Changing Web Themes In Asp.Net

Example Pages with Web Themes settings

When we start this example website, it first displays the home page. We can select a product and submit it to move to the Order Confirmation page. The order confirmation page has labels to provide order confirmation and the same page also has a link called ‘Home’ to navigate back to the homepage. From the homepage, we can navigate to the Web Admin Page where we can set the theme for the entire website. We can select a theme in the web admin page and apply that theme to the whole site (In our case it contains only three pages) by clicking the ‘apply’ button. From the web admin page, we can go to the main web page by using the home link.

All three pages use two themes named Ocean and Desert. By default, when we launch the site for the first time, we do not apply any theme. So we should go to the web admin page and from there we can apply a theme. The code behind in the web admin page uses the session variable for demo purpose. You should use application variables for real websites.

Continue Reading →

AppSettings – Dynamically Adding & Updating

Dynamic AppSettings C# Example

In the last article, we saw how to use the app.config file, its hierarchy, and preference in picking the App settings. In this article, we will see updating the app.config file at runtime. The article example shows adding, deleting and updating a Key-Value entry in the appSettings Section of app.config file. Note, all the settings related to the App goes under the appSettings section.

In the above example, the result of the action performed on the App.config file is passed on to the user through the ‘Display Area’. To add (Button Marked as 5) a setting to the app.config file, the key and value should be keyed-in in the Setting Key, Setting Value text boxes marked as 2 and 3 in the screenshot. The user should mention the key in the Setting Key text box to get (Marker 6) the AppSetting entry from the ‘App.Config’. We show the retrieved key in the display area and in the Setting value. To adjust (Through button marker 7) an existing setting, the user will point out the existing key and changed value in the Setting Key and Setting Value, respectively. To delete (Marker 8) a key, the user will specify it in the Setting Key. Note we do all these actions at run time.

Continue Reading →