Acme.Northwind.Install.SqlServers.ExtendedPropertyExists C# (CSharp) Метод

ExtendedPropertyExists() приватный статический Метод

private static ExtendedPropertyExists ( string connectionString, string property, string user, string table, string column ) : bool
connectionString string
property string
user string
table string
column string
Результат bool
		private static bool ExtendedPropertyExists(string connectionString, string property, string user, string table, string column)
		{
			bool retval = false;
			if (CanUseExtendedProperty(connectionString))
			{
				string userName = string.Empty;
				string userValue = string.Empty;
				string tableName = string.Empty;
				string tableValue = string.Empty;
				string columnName = string.Empty;
				string columnValue = string.Empty;

				property = "'" + property + "'";
				if (user == string.Empty)
				{
					userName = "NULL";
					userValue = "NULL";
				}
				else
				{
					userName = "'user'";
					userValue = "'" + user + "'";
				}
				if (table == string.Empty)
				{
					tableName = "NULL";
					tableValue = "NULL";
				}
				else
				{
					tableName = "'table'";
					tableValue = "'" + table + "'";
				}
				if (column == string.Empty)
				{
					columnName = "NULL";
					columnValue = "NULL";
				}
				else
				{
					columnName = "'column'";
					columnValue = "'" + column + "'";
				}

				System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection();
				System.Data.SqlClient.SqlDataReader externalReader = null;
				try
				{
					conn.ConnectionString = connectionString;
					conn.Open();
					SqlCommand command = new SqlCommand();
					command.CommandText = String.Format("SELECT value FROM ::fn_listextendedproperty({0}, {1}, {2}, {3}, {4}, {5}, {6})", new object[] { property, userName, userValue, tableName, tableValue, columnName, columnValue });
					command.CommandType = System.Data.CommandType.Text;
					command.Connection = conn;
					externalReader = command.ExecuteReader();
					if (externalReader.Read())
					{
						retval = true;
					}
				}
				catch (Exception ex)
				{
					throw ex;
				}
				finally
				{
					if (externalReader != null)
						externalReader.Close();
					if (conn != null)
						conn.Close();
				}
			}
			return retval;
		}
		#endregion