Wednesday, January 31, 2007

Friday, January 19, 2007

C# Passing Comma Seperated Stored Procedure Paramter

I came across passing a very long comma seperated string as a Stored Procedure Parameter. There is character limit on SqlParameter, that is one. The second thing I didn't want to pass individual string as parameters and calling same Stored Procedure for each string. That would have been clear and present performance hit. So I wrote following piece of code to avoid this situation. Break large string into small strings that can be accepted by SqlParameter.

string tmpMatterSpaceNames = string.Empty;
int lowerLimit = Constants.SqlParamCharLimit - 200;
StringCollection objStrCollection = new StringCollection();
foreach (string matterSpaceName in objNV.AllKeys)
{
tmpMatterSpaceNames += "'" + matterSpaceName + "',";
if (tmpMatterSpaceNames.Length > lowerLimit)
{
tmpMatterSpaceNames = Regex.Replace(tmpMatterSpaceNames, @",$", "");
objStrCollection.Add(tmpMatterSpaceNames);
tmpMatterSpaceNames = string.Empty;
}
}
if (tmpMatterSpaceNames != string.Empty)
{
tmpMatterSpaceNames = Regex.Replace(tmpMatterSpaceNames, @",$", "");
objStrCollection.Add(tmpMatterSpaceNames);
}

foreach (string matterSpaceNames in objStrCollection)
objMSDao.UpdateSourceCreatedFlag (matterSpaceNames, true);

Saturday, January 13, 2007

A Day in the Life of Indian Village

In Pragati Maidan Delhi, I find this place pretty interesting. This place presents models of indian villages across the different cultures. You can also see old household, crockeries and bull carts here. Posted by Picasa