Repeater Control - How to get formatted date as ouput on a page having Repeater Control

If you are tired of getting dates in your repeater control as shown in the following figure unformatted and you want to get dates in some custom format then simply you can use the ToString() method with some parameters to convert it into desired format as shown below. formattd You just have to enter this small piece of code to achieve this repeater   For further information on DateTime formats please visit this link http://msdn.microsoft.com/en-us/library/az4se3k1.aspx


PowerMenu:- Very useful utility by which you can minimize any application to tray

  1. I am using Power Menu from years now it is a tiny but very useful utility especially its minimize to tray is the feature which i use the most.
  2. So i thought to share this with you all.

PowerMenu   You can download power  menu from below given links:- Installer --------http://www.abstractpath.com/powermenu/PowerMenuSetup_1_5_1.exe Portable Version--------http://www.abstractpath.com/powermenu/PowerMenu_1_5_1.zip


Websites to check whether your pages are served after compression or not.

  1. http://www.pipeboost.com
  2. http://www.port80software.com/products/httpzip/compresscheck

These are among the few websites which can check and give you in detail picture of how your webpages are working with and without compression. IIS compression using Gzip is preferred over the default deflate compression as browsers have gzip as their first search string thus pages with gzip loads faster although some people can argue that deflate is faster than gzip. How to enable gzip compression in your static and dynamic pages this we will cover in the next article. Given here are the results tested from port80software.com on compression test of a dummy website. gzip


Disabling IE Enhanced Security Configuration for WS2003

  1. Go to Add/Remove Windows Components in the Add/Remove Programs Dialogue Box and uncheck the Internet Explorer Enhanced Security Configurationieenhanced1

2.If uninstalling this feature also doesn't work for you then you can give this a try:-    Go to  HKCUSoftwareMicrosoftWindowsCurrentVersionInternet
SettingsZoneMapIEHarden
if you find this entry and its value is 1 this means that IE Enhanced Security is enabled for the given user.So just play with the value and make it 0.This works in certain cases but not applicable to all just give it a try,test it and your comments are always welcome.


When to use using and when to use try catch to do the cleaning

  1. We have two ways to clean up utilized resources in C# either we can use try..catch..finally statements series or we can use the using statement in C#
  2. The thing is that resources should be released and cleanup must be performed either before exitting the using block or just entering up the finally block.
  3. Use using Statement in C# to release up the resources when the creating type implements the IDisposable interface.
  4. Use try..catch..finally when we need to perform cleanup but not necessarily employ the Dispose Method.

Installing Intel X3100 Graphics Driver on Toshiba Sattellite M200 Laptops having WS2003 as Operating Sytem

Those of you who are having trouble in installing X3100 Graphics Driver on Toshiba Satellite M200 and similar laptops in that series, the problem is that the driver that toshiba people have on their site is old version and it works only on Windows XPSP2 and later OS,it does not work on Windows Server 2003 OS. So the solution is just download the Graphics Driver for Windows XP for Dell Inspiron 1525. These dell people have latest  driver and it install very smoothly on Windows Server 2003. If this also is not working for you than you can add setup.exe in the application verifier and do the proceeding as given in this post. https://www.smallworkarounds.com/index.php/2008/09/17/installing-photoshop-cs3-on-windows/


Anonymous Types in C#

  1. Anonymous types in C# are a new concept which shipped with .net framework 3.5
  2. Anonymous types are nothing but it simply states that we dont have to define a type and that type is defined automatically by C# analysing the right hand side.
  3. Anonymous Types are very important in the LINQ word.
  4. Keyword var is used to declare an anonymous type.
  5. They are immutable and thus dont require any property getter or setter methods
  6. They must always be initialized so that the compiler can build the type defination and bind the anonymous type with that , and it is only possible only when we have any thing in the right hand side of an anonymous type thus anonymous types should always be initialized.

//1.Shows Simple anonymous varible declarations and iterating using for loop

 1: var fabonici = new int[]{1,1,2,3,5,8,13,21};
 2: for( var i = 0; i<fabonici.Length; i++)
 3: Console.WriteLine(fabonici[i]);
 4:

//2.Show Simple anonymous variable declarations and iterating using foreach loop

 1: var fabonici = new int[]{1,1,2,3,5,8,13,21};
 2: foreach (var fibo in fabonici)
 3: Console.WriteLine(fibo);

//3.Linq query used as iterand in foreach statement.

 1: var fabonici = new int[]{1,1,2,3,5,8,13,21};
 2: foreach (var fibo in
 3: from f in fabonici
 4: where f%3 == 0
 5: select f)
 6: Console.WriteLine(fibo);

Custom DAL having functions which recieve StoredProcedure Name and SortedList having key/value pairs as parameters to reduce code duplicacy by minimizing open() and close() connection.

Mostly whenever we code an enterprise project we should follow the n-tier model and divide our project into various tiers. Lets continue from the UI,so first tier is our UI ,from the UI we should we should make use of our Model layer objects which simply contains classes which map our requirements for the projects. Now from UI,we should create objects of Model Classes and pass these model classes to the Service class.This service class is nothing but it contains all the static functions which we require in our projects.Most of the application's service logic is applied in these classes, or we can say that these classes serve the Model Objects behaviour. Next comes the most important layer called Utility or some people might Directly call it DAL layer. Anyways the function of this layer is to interact with the Service Layer on one hand and on the other hand fetch and persist result to the database either using ad-hoc queries or using the stored procedure logic.Given below is the representation of this n-tier project arichitecture

In this article we will mainly concentrate on the DAL part or the last layer or tier in our architecture.In our model we are not using ad-hoc queries but only stored procedures.So we have developed a SqlHelper file which will recieve only the names of stored procedure and a sorted list having a key value pair of parameters which we will pass to the stored procedure. This layer will also handle every opening and closing of the connection to the database.We generally return a reader from the database to any point in our code but here we don't want to open and close connection in the application logic so we are converting the reader fetched from the database to the dataset and then finally returning the dataset in the application. There are various functions used in order to achieve this logic i will describe here a few important ones.You can download the whole file which is attached at the end of this article.

 1: public static void DBExecuteNonQuery(string storedProcedure, SqlCommand command)
 2: {
 3: using (var connection = new SqlConnection(ConnectionString))
 4: {
 5: connection.Open();
 6: command.CommandText = storedProcedure;
 7: command.Connection = connection;
 8: command.CommandType = CommandType.StoredProcedure;
 9: command.ExecuteNonQuery();
 10: }
 11: }

We are not using above function directly from the application service layers but it is being called from inside another sqlhelper function called "ConvertToSqlCommandForNonQuery" although it can be directly used but we want to follow our key,value transfer from the application thus we follow this pattern.So below given is our ConvertToSqlCommandForNonQuery function which takes stored procedure name and sortedlist as parameters,then it calls the DBExecuteNonQuery which we have seen just above after making a command out of the recieved SoretedList.

In this function we are also using a ConvertToSqlDBType function, it is used because the value we recieve as object and we now have to map the objects C# type to Sql Server Database type.So we have another function called ConvertToSqlDBType to achieve this.We will talk about it later.

 1: public static void ConvertToSqlCommandForNonQuery(string storedProcedure, SortedList<string, object> values)
 2: {
 3: var command = new SqlCommand();
 4: foreach (var value in values)
 5: {
 6: Type type = value.Value.GetType();
 7: SqlDbType sqlDBType = ConverToSqlDBType(type);
 8: command.Parameters.Add(value.Key, sqlDBType).Value = value.Value;
 9: }
 10: DBExecuteNonQuery(storedProcedure, command);
 11: }
Usage of above function is give below here SaveCategory recieves a model layer object called Category which contains information about the Category newly added now to persist these changes to Database we call our SqlHelper files ConvertToSqlCommandForNonQuery function and pass the name of the stored procedure and the parameterlist to the function.
Remember that ConvertToSqlCommandForNonQuery is used only when we want to insert,update or delete functions.
 1: public static void SaveCategory(Category category)
 2: {
 3: var parameterList = new SortedList<string, object>();
 4: parameterList.Add("categoryName", category.CategoryName);
 5: SqlHelper.ConvertToSqlCommandForNonQuery("usp_SaveCategory", parameterList);
 6: }
Similarly is the below given function called "DBExecuteScalar" it also takes a stored procedure name and a sortedlist as inputs and return the integer value.
This function also internally calls "DBExecuteScalar(string storedprocedurename,SqlCommand command)" like the above function
 1: public static Int32 DBExecuteScalar(string storedProcedure, SqlCommand command)
 2: {
 3: Int32 value = 0;
 4: using (var connection = new SqlConnection(ConnectionString))
 5: {
 6: connection.Open();
 7: command.CommandText = storedProcedure;
 8: command.Connection = connection;
 9: command.CommandType = CommandType.StoredProcedure;
 10: value = (Int32) command.ExecuteScalar();
 11: }
 12: return value;
 13: }

 

 1: public static Int32 DBExecuteScalar(string storedProcedure, SortedList<string, object> values)
 2: {
 3: var command = new SqlCommand();
 4: foreach (var value in values)
 5: {
 6: Type type = value.Value.GetType();
 7: SqlDbType sqlDBType = ConverToSqlDBType(type);
 8: command.Parameters.Add(value.Key, sqlDBType).Value = value.Value;
 9: }
 10: int retValue = DBExecuteScalar(storedProcedure, command);
 11: return retValue;
 12: }

 

Third set of functions are the main functions which first convert the datareader returned from the stored procedure to the dataset and then return this dataset to the application.We can very well return the datareader to the application and then iterate till the end of the reader but we are not doing here because we dont want to carry the opened connection to the application or simply we want to limit the connection flow only to the DAL layer.

 1: public static DataSet DBExecuteReader(string storedProcedure)
 2: {
 3: SqlDataReader reader = null;
 4: var command = new SqlCommand();
 5: using (var connection = new SqlConnection(ConnectionString))
 6: {
 7: connection.Open();
 8: command.CommandText = storedProcedure;
 9: command.Connection = connection;
 10: command.CommandType = CommandType.StoredProcedure;
 11: reader = command.ExecuteReader();
 12:
 13: var dataSet = new DataSet();
 14: do
 15: {
 16:
 17: DataTable schemaTable = reader.GetSchemaTable();
 18: var dataTable = new DataTable();
 19:
 20: if (schemaTable != null)
 21: {
 22: for (int i = 0; i < schemaTable.Rows.Count; i++)
 23: {
 24: DataRow dataRow = schemaTable.Rows[i];
 25: var columnName = (string) dataRow["ColumnName"];
 26: var column = new DataColumn(columnName, (Type) dataRow["DataType"]);
 27: dataTable.Columns.Add(column);
 28: }
 29:
 30: dataSet.Tables.Add(dataTable);
 31: while (reader.Read())
 32: {
 33: DataRow dataRow = dataTable.NewRow();
 34:
 35: for (int i = 0; i < reader.FieldCount; i++)
 36: dataRow[i] = reader.GetValue(i);
 37:
 38: dataTable.Rows.Add(dataRow);
 39: }
 40: }
 41: else
 42: {
 43:
 44:
 45: var column = new DataColumn("RowsAffected");
 46: dataTable.Columns.Add(column);
 47: dataSet.Tables.Add(dataTable);
 48: DataRow dataRow = dataTable.NewRow();
 49: dataRow[0] = reader.RecordsAffected;
 50: dataTable.Rows.Add(dataRow);
 51: }
 52: } while (reader.NextResult());
 53: return dataSet;
 54: }
 55: }
 1: public static DataSet DBExecuteReader(string storedProcedure, SqlCommand command)
 2: {
 3: SqlDataReader reader = null;
 4: using (var connection = new SqlConnection(ConnectionString))
 5: {
 6: connection.Open();
 7: command.CommandText = storedProcedure;
 8: command.Connection = connection;
 9: command.CommandType = CommandType.StoredProcedure;
 10: reader = command.ExecuteReader();
 11:
 12:
 13: var dataSet = new DataSet();
 14: do
 15: {
 16:
 17: DataTable schemaTable = reader.GetSchemaTable();
 18: var dataTable = new DataTable();
 19:
 20: if (schemaTable != null)
 21: {
 22:
 23: for (int i = 0; i < schemaTable.Rows.Count; i++)
 24: {
 25: DataRow dataRow = schemaTable.Rows[i];
 26:
 27: var columnName = (string) dataRow["ColumnName"];
 28:
 29: var column = new DataColumn(columnName, (Type) dataRow["DataType"]);
 30: dataTable.Columns.Add(column);
 31: }
 32:
 33: dataSet.Tables.Add(dataTable);
 34:
 35:
 36: while (reader.Read())
 37: {
 38: DataRow dataRow = dataTable.NewRow();
 39:
 40: for (int i = 0; i < reader.FieldCount; i++)
 41: dataRow[i] = reader.GetValue(i);
 42:
 43: dataTable.Rows.Add(dataRow);
 44: }
 45: }
 46: else
 47: {
 48:
 49: var column = new DataColumn("RowsAffected");
 50: dataTable.Columns.Add(column);
 51: dataSet.Tables.Add(dataTable);
 52: DataRow dataRow = dataTable.NewRow();
 53: dataRow[0] = reader.RecordsAffected;
 54: dataTable.Rows.Add(dataRow);
 55: }
 56: } while (reader.NextResult());
 57: return dataSet;
 58: }
 59: }

 

 1: public static DataSet ConvertToSqlCommand(string storedProcedure, SortedList<string, object> values)
 2: {
 3: var command = new SqlCommand();
 4: foreach (var value in values)
 5: {
 6: Type type = value.Value.GetType();
 7: SqlDbType sqlDBType = ConverToSqlDBType(type);
 8:
 9: command.Parameters.Add(value.Key, sqlDBType).Value = value.Value;
 10:
 11: }
 12: DataSet dataSet = DBExecuteReader(storedProcedure, command);
 13: return dataSet;
 14: }

 

Given below is the example of the "ConvertToSqlCommand" function.Here we are populating all the categories of a particular user.

 1: public static List<Category> PopulateUserCategory(int userID)
 2: {
 3: var categoryList = new List<Category>();
 4: var parameterList = new SortedList<string, object>();
 5: parameterList.Add("@userID", userID);
 6: DataSet dataSet = SqlHelper.ConvertToSqlCommand("usp_GetAllCategoriesByUserID", parameterList);
 7: DataTable dataTable = dataSet.Tables[0];
 8: foreach (DataRow dataRow in dataTable.Rows)
 9: {
 10: var category = new Category();
 11: category.CategoryID = Convert.ToInt32(dataRow["CategoryID"]);
 12: category.CategoryName = Convert.ToString(dataRow["CategoryName"]);
 13: categoryList.Add(category);
 14: }
 15: return categoryList;
 16: }

 

This is the "ConvertToSqlDBType" function which we use to convert C# types to SqlDBTypes.Given below are some common type conversions you can very well enhance this list and do whatever you feel like.

 1: public static SqlDbType ConverToSqlDBType(Type systemType)
 2: {
 3:
 4: switch (systemType.Name)
 5: {
 6: case "Int32":
 7: return SqlDbType.Int;
 8: case "String":
 9: return SqlDbType.NVarChar;
 10: case "DateTime":
 11: return SqlDbType.DateTime;
 12: case "Boolean":
 13: return SqlDbType.Bit;
 14: default:
 15: return SqlDbType.VarChar;
 16: }
 17: }

Conclusion

So above was an article on how to follow a layerd approach in an n-tier enterprise solution and this article also gave a small insight on how to handle Database calls from within the Data Access Layer and also how to efficiently opening and closing the database connection.
It also talked about the various functions which we have designed in order to talk to the database.
You are free to extend it and modify it according to your needs and use it inside your projects.
Uploaded Below is the SqlHelper.cs file which achieves the desired result.

rpc_relay

canvas

<html> <head>
<style type="text/css">
/*
These styles are customizable.
Provide  .canvas-gadget (the div that holds the canvas mode gadget)
at least 500px width so that  the gadget has sufficient screen real estate
*/
body {
margin: 0;
font-family:arial, sans-serif;
text-align:center;
}
.container {
width:652px;
margin:0 auto;
text-align:left;
}
.fc-sign-in-header {
text-align:left;
font-size: 13px;
padding:3px 10px;
border-bottom:1px solid #000000;
}
.signin {
text-align:left;
float:right;
font-size: 13px;
height: 32px;
}
.go-back {
text-align:left;
margin:5px auto 15px auto;
}
.go-back a, .go-back a:visited {
font-weight:bold;
}
.canvas-gadget {
text-align:left;
width:650px; /* ALLOW AT LEAST 500px WIDTH*/
margin:10px auto 10px auto;
border:1px solid #cccccc;
}
.site-header {
margin-top: 10px;
}
.section-title {
font-size: 2em;
}
.clear {
clear:both;
font-size:1px;
height:1px;
line-height:0;
margin:0;
padding:0;
}
</style>
<script type="text/javascript" src="