Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Detemining Variable Type
Message
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00952752
Message ID:
00952776
Views:
7
Use

BuildStringArray.GetType() == typeof(System.String)

etc.



>Hi All,
>
>I have a good question, well I think it is a good question...
>
>I have a object Array and I pass values to this object array such as "12",456.89, 122
>
>I want to determine the type of each variable as it affects the way I will build by dynamic where clause.
>
>this is what I have so far.
>
>But I get an error on the comparing of system.int to the object.getType function look for ********************> to see the starting line I am talking about.
>
>The error is : 'short' denotes a 'class' where a 'variable' was expected
>
>
>
>using System;
>using OakLeaf.MM.Main;
>
>namespace Apps4u.WinApp.Business.Search
>{
>	/// <summary>
>	/// The SearchCritieria Class will contain functions to manipulate and validate the search criteria
>	/// </summary>
>	public class SearchCriteria
>	{
>		
>		protected bool SearchValidate_Completed_ErrorFree = false;
>
>		public SearchCriteria()
>		{
>		}
>
>		/// <summary>
>		/// This method will validate the string to ensure it has no invalid characters in it.
>		/// </summary>
>		/// <param name="SearchArray">receives an Object Array from the GUI</param>
>		/// <returns>Returns True or False</returns>
>		public bool SearchValidateStrings(params object[] SearchArray)
>		{
>			
>			foreach (object ValidDataArray in SearchArray)
>			{
>				// TODO : Add a regular expression search here to validate the array elements
>				// if (string is not valid)
>				// {this.SearchValidate_Completed_ErrorFree = false; break;}
>			}
>			return this.SearchValidate_Completed_ErrorFree;
>		}
>
>		/// <summary>
>		/// This method will build a string where clause
>		/// </summary>
>		/// <param name="SearchArray"></param>
>		/// <returns></returns>
>		public string BuildSearchWhereClause(params object[] SearchArray)
>		{
>			if (!this.SearchValidate_Completed_ErrorFree) return "";
>
>			string sWhereClause, sFieldName1, sFieldName2 = "";
>			bool lIsNotEmpty_Object = false;
>			bool lOnFirstItem = true;
>
>			foreach (object BuildStringArray in SearchArray)
>			{
>				// the first object is the field name which should always have a value
>				// the second object is suppose to be the value from the form.
>				// so we will test if the second object has a value
>				if (lOnFirstItem)
>				{
>					lOnFirstItem = false;
>					sFieldName1 = BuildStringArray.ToString();
>				}
>				else
>				{
>					lOnFirstItem = true;
>					sFieldName2 = BuildStringArray.ToString() ;
>				}
>					
>				// test to see if we have a value
>				if (!mmString.Empty(sFieldName2)) lIsNotEmpty_Object = true;
>
>				if (lIsNotEmpty_Object)
>				{
>					if (!mmString.Empty(sWhereClause)) sWhereClause += " AND ";
>********************>
>					if (BuildStringArray.GetType() == System.Int16 || BuildStringArray.GetType() == System.Int32 || BuildStringArray.GetType() == System.Int64  )
>					{ sWhereClause += sFieldName1 + " = " + sFieldName2 ;}
>					else if (BuildStringArray.GetType() == System.DateTime)
>					{ sWhereClause += sFieldName1 + " = {" + sFieldName2 + "}";}
>					else if (BuildStringArray.GetType() == System.String)
>					{ sWhereClause += sFieldName1 + " = '" + sFieldName2 + "'";}
>					
>				}
>			}
>			return "";
>		}
>		
>	}
>}
>
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform