Jeffrey Richter has written a nice article on performance of Local variable V/s Field in a C# class.
Monday, May 28, 2007
Thursday, May 17, 2007
Localizing a Windows Form
Always have a question mark about how to do localization for a windows Form application. So taken this challenge and here the steps goes
1. Create a Windows Forms Project.
2. Set the Localizable property of Form to True.
3. A resx file is created per window form.
4. Add Control Name.Text as Name and its value to “My Form”. The convention of the name is Control Name.Property Name
5. A resource file generated per language i.e. if you would like to support 5 languages then need to have 5 resx file. Each one following MS specified naming convention.
6. Initializes the ResourceManager
ResourceManager resMgr = new ResourceManager(,
Assembly.GetExecutingAssembly());
Here while providing the name of the form provide the fully qualified name of the form class name i.e. with namespace.
7. Initializes the Culture based on the language selected, assumming there is config file where the locale is set
locale = ConfigurationManager.AppSettings["LOCALE"];
if (locale == “DEFAULT”)
Thread.CurrentThread.CurrentUICulture = CultureInfo.InstalledUICulture;
else
Thread.CurrentThread.CurrentUICulture = new CultureInfo(locale);
8. Now use the ResourceManager to read the read the corresponding culture string
this.Text = resMgr.GetString(“<Control Name>. <Property Name>”, Thread.CurrentThread.CurrentUICulture);
The above set the Text property of the Form to the corresponding localized string.
Wednesday, May 16, 2007
Saturday, May 12, 2007
Retrieving Stored Procedures Parameter Info using ADO.NET
The below code provides way to retrieve meta information about the stored procedure argument
//The usual code
OleDbConnection dbConnection = new OleDbConnection(<Connection string>);
OleDbCommand dbCommand = new OleDbCommand(<sp name>,dbConnection);
dbCommand.CommandType = CommandType.StoredProcedure;
//The FUNCTION
OleDbCommandBuilder.DeriveParameters(dbCommand);
The above static DeriveParameters method retrieve information about stored procedure specified by the command object.
//Iterating over the Parameter and retrieving the meta information….
foreach(OleDbParameter param in discoveredParameters)
{
Console.WriteLine(“Name Of Parameter:{0}”,param.ParameterName);
Console.WriteLine(“Data Type: {0}”,param.OleDbType.ToString());
Console.WriteLine(“Input/Input-Output: {0}”,param.Direction.ToString());
Console.WriteLine(“Size:{0}”,param.Size);
}
