trunk/src/LythumOSL.Core/Data/Helpers.cs
/// <summary>
/// This method is designet for any datatable 
/// which needs to add first row with any value and name.
/// It also adds system column, where all items will be set to 0
/// except newly added item, it will be set to 1
/// </summary>
/// <param name="sourceTable"></param>
/// <param name="names"></param>
/// <param name="values"></param>
/// <returns></returns>
This method is designet for any datatable
which needs to add first row with any value and name.
It also adds system column, where all items will be set to 0
except newly added item, it will be set to 1
This method is designet for any datatable which needs to add first row with any value and name . It also adds system column where all items will be set to 0 except newly added item it will be set to 1
public static DataTable CraftTableWithSystem (
			DataTable sourceTable,
			string[] names,
			object[] values)
		{
			DataTable retVal = null;
			if (sourceTable != null)
			{
				retVal = sourceTable.Copy ();
				DataColumn col = new DataColumn("system");
				col.DefaultValue = "0";
				retVal.Columns.Add (col);
				if (names != null && values != null)
				{
					if (names.Length <= values.Length)
					{
						DataRow r = retVal.NewRow ();
						r["system"] = "1";
						for (int i = 0; i < names.Length; i++)
						{
							if (values[i] == null)
							{
								r[names[i]] = DBNull.Value;
							}
							else
							{
								r[names[i]] = values[i];
							}
						}
						retVal.Rows.InsertAt (r, 0);
					}
				}
			}
			return retVal;
		}
public static DataTable CraftTableWithSystem ( DataTable sourceTable , string [ ] names , object [ ] values ) { DataTable retVal = null ; if ( sourceTable != null ) { retVal = sourceTable . Copy ( ) ; DataColumn col = new DataColumn ( " " ) ; col . DefaultValue = " " ; retVal . Columns . Add ( col ) ; if ( names != null && values != null ) { if ( names . Length <= values . Length ) { DataRow r = retVal . NewRow ( ) ; r [ " " ] = " " ; for ( int i = 0 ; i < names . Length ; i ++ ) { if ( values [ i ] == null ) { r [ names [ i ] ] = DBNull . Value ; } else { r [ names [ i ] ] = values [ i ] ; } } retVal . Rows . InsertAt ( r , 0 ) ; } } } return retVal ; }
This method is designet for any datatable
which needs to add first row with any value and name.
This method is designet for any datatable which needs to add first row with any value and name .
None
sourceTable
DataTable
None
names
string[]
None
values
object[]
None