Programming Examples

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

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 →

Understanding & Using AppConfig File

AppConfig File C# Example

Let us say we are writing an Internet modem device monitor service application. The duty of the application will be tracking for Upload and download action of the modem. When there is a large download say 500KB per second for past 10 Minutes, the device should assert that to a user. The intimation can be done either by blinking a Red LED in the modem device or by making continues beep or by making the entire desktop with a red transparent overlay. But which option the utility should choose from? Now I hear you are saying keep it as an ‘Application Setting’. In C#, it is AppConfig file.

In old days, Legacy windows desktop software uses section-based Initialization Config Files (‘INI Files’) and App reads and writes from it. The coder places the settings on sections, which are nothing but organizing the settings under a certain group. Now in dot net days, Microsoft replaced the INI files as AppConfig files. They place the App settings in the XML format in application config files aka AppConfig file. In this article, we will explore how to make use of the AppConfig file. For exploring, we will create a simple C# Windows Form based example.

Continue Reading →

Hooking CustomValidator Control & Javascript

CustomValidator & Java-script Scripting

Validation controls are useful to perform the validation on the web forms. The framework provides validation controls like RequiredFieldValidator, RangeValidator and CompareValidator, etc. Sometimes, these validation controls are not fair to do the special validations. In those cases, we will go for the CustomValidator Control. In this example we will walk through the usage of the CustomValidator Control and learn how to link the java script function as the validation function.

Continue Reading →

Updating Table Data Via SQL Views

Joins and Calculated Columns

An SQL View is nothing but a select query with a name given to it or we can say a view is a ‘Named Query’. Why we need a view? There will be a lot of answers for this. Some important answers are below:

1) A View can bring data from many tables by using suitable joins and while bringing so, it may use complex filters and calculated data to form the needed result set. In user point of view, all these complications are hidden, and they feel that they are pulling data from a single table.
2) Some time for security reasons, access to the table and its private details like table schema and relations are not given to the DB users. All they have is access to a view without the knowledge of what tables are actually sitting in the DB.
3) Using the view, the DB admin can restrict an user to update only some portions of the records.

Continue Reading →

Ado.Net SqlCommand Example

ExecuteReader ExecuteNonQuery ExecuteScalar Block Diagram

To fetch data from the database, we need DB connection. In ADO.Net, based on the Database Provider, there are distinct connection classes. For example, to hook up to an Oracle Database we need to use OracleConnection and in the same way we need SqlConnection to hook up to the SQL Server database. The Command Object is also database specific. For Example, SqlCommand object can talk with SQL Server DB through SqlConnection object and OracleCommand object can talks to the Oracle DB through OracleConnection. These command objects know what needs to be executed in the database. In this article, we will study how to use SqlCommand and its methods ExecuteScalar, ExecuteReader and ExecuteNonQuery.

Continue Reading →