SqlParser.cs
/// <summary>
/// Stringifiy the sql IN Element Set
/// </summary>
/// <param name="elementSet"></param>
/// <param name="columnDataType"></param>
/// <returns>return list converted to string</returns>
Stringifiy the sql IN Element Set
Stringifiy the sql IN Element Set
private string StringifiyElementSet(IList<string> elementSet, ColumnDataType columnDataType)
		{
			var elementSetString = string.Empty;
			switch (columnDataType)
			{
				case ColumnDataType.Numeric:
					elementSetString = string.Join(",", elementSet);
					break;
				case ColumnDataType.Date:
					for (var counter = 0; counter < elementSet.Count; counter++)
					{
						var element = elementSet[counter];
						if (DateTime.TryParse(element, out DateTime dateValue))
						{
							elementSet[counter] = string.Format("CONVERT(datetime,'{0}')", dateValue.ToString("yyyy-MM-dd"));
						}
						else
						{
							return string.Empty;
						}
					}
					elementSetString = string.Join(",", elementSet);
					break;
				case ColumnDataType.Text:
					for (var counter = 0; counter < elementSet.Count; counter++)
					{
						var element = elementSet[counter];
						elementSet[counter] = string.Format("'{0}'", element);
					}
					elementSetString = string.Join(",", elementSet);
					break;
				case ColumnDataType.Boolean:
					for (var counter = 0; counter < elementSet.Count; counter++)
					{
						var element = elementSet[counter]; 
						var result = false;
						if (bool.TryParse(element.ToLower(), out result))
						{
							elementSet[counter] = result ? "1" : "0";
						}
						else
						{
							elementSet[counter] = string.Empty;
						}
						if (string.IsNullOrWhiteSpace(elementSet[counter]))
						{
							break;
						}
					}
					elementSetString = string.Join(",", elementSet);
					break;
				default:
					elementSetString = string.Empty;
					break;
			}
			return elementSetString;
		}
private string StringifiyElementSet ( IList < string > elementSet , ColumnDataType columnDataType ) { var elementSetString = string . Empty ; switch ( columnDataType ) { case ColumnDataType . Numeric : elementSetString = string . Join ( " " , elementSet ) ; break ; case ColumnDataType . Date : for ( var counter = 0 ; counter < elementSet . Count ; counter ++ ) { var element = elementSet [ counter ] ; if ( DateTime . TryParse ( element , out DateTime dateValue ) ) { elementSet [ counter ] = string . Format ( " " , dateValue . ToString ( " " ) ) ; } else { return string . Empty ; } } elementSetString = string . Join ( " " , elementSet ) ; break ; case ColumnDataType . Text : for ( var counter = 0 ; counter < elementSet . Count ; counter ++ ) { var element = elementSet [ counter ] ; elementSet [ counter ] = string . Format ( " " , element ) ; } elementSetString = string . Join ( " " , elementSet ) ; break ; case ColumnDataType . Boolean : for ( var counter = 0 ; counter < elementSet . Count ; counter ++ ) { var element = elementSet [ counter ] ; var result = false ; if ( bool . TryParse ( element . ToLower ( ) , out result ) ) { elementSet [ counter ] = result ? " " : " " ; } else { elementSet [ counter ] = string . Empty ; } if ( string . IsNullOrWhiteSpace ( elementSet [ counter ] ) ) { break ; } } elementSetString = string . Join ( " " , elementSet ) ; break ; default : elementSetString = string . Empty ; break ; } return elementSetString ; }
Stringifiy the sql IN Element Set
Stringifiy the sql IN Element Set
return list converted to string
return list converted to string
elementSet
IList<string>
None
columnDataType
ColumnDataType
None