public object BaseTableNameToID(String Tablename, String Name, Boolean insertUnknown = false)
{
try
{
String fullTableName = String.Format("tb{0}", Tablename);
if (Name == null)
return null;
else
{
DataRow[] data = m_BaseData.Tables[fullTableName].Select(String.Format("{0} = '{1}'", Tablename, Name));
if ((data.GetUpperBound(0) == -1) && insertUnknown)
{
int maxValue;
DataTable Table = m_BaseData.Tables[fullTableName];
if (Table.Rows.Count > 0)
maxValue = Convert.ToInt32(Table.Compute("Max(id)", string.Empty));
else
maxValue = 0;
DataRow newRow = Table.NewRow();
newRow["id"] = maxValue + 1;
newRow[Tablename] = DBConnector.DTEscape(Name);
Table.Rows.Add(newRow);
PrepareBaseTables(fullTableName, true);
}
return (Int32)(m_BaseData.Tables[fullTableName].Select(String.Format("{0} = '{1}'", Tablename, Name))[0]["id"]);
}
}
catch (Exception ex)
{
throw new Exception(String.Format("Error while searching for the id of <{0}> in table <tb{1}>", Name, Tablename), ex);
}
}