Пример #1
0
        public string GetTableId(string connectionString, string databaseName, string tableName)
        {
            if (WebConfigUtils.IsMySql)
            {
                return(tableName);
            }

            if (string.IsNullOrEmpty(connectionString))
            {
                connectionString = ConnectionString;
            }

            var tableId = SqlUtils.Cache_GetTableIDCache(databaseName, tableName);

            if (string.IsNullOrEmpty(tableId))
            {
                string sqlString =
                    $"select id from [{databaseName}].dbo.sysobjects where type in ('U','V') and category<>2 and name='{tableName}'";

                using (var rdr = ExecuteReader(connectionString, sqlString))
                {
                    if (rdr.Read())
                    {
                        tableId = GetString(rdr, 0);
                        SqlUtils.Cache_CacheTableID(databaseName, tableName, tableId);
                    }
                    rdr.Close();
                }
            }

            return(tableId);
        }