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);
Blogs on .NET and LAMP Technologies
There's often more than one correct thing.
There's often more than one right thing.
There's often more than one obvious thing.
--Larry Wall
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.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment